powershell - What is the @ parameter? -
in powershell, few programs starts @'
, ends '@
, when type @'
, press enter in powershell prompt throws error. can explain how can go this?
@'...'@
, @"..."@
"here strings" (documented in about_quoting_rules):
here-strings
the quotation rules here-strings different.
a here-string single-quoted or double-quoted string in quotation marks interpreted literally. here-string can span multiple lines. lines in here-string interpreted strings though not enclosed in quotation marks.
like regular strings, variables replaced values in double-quoted here-strings. in single-quoted here-strings, variables not replaced values.
you can use here-strings text, particularly useful following kinds of text:
-- text contains literal quotation marks -- multiple lines of text, such text in html or xml document -- text script or function
a here-string can have either of following formats, represents linefeed or newline hidden character added when press enter key.
double-quotes:
@"<enter> <string> [string] ...<enter> "@
single-quotes:
@'<enter> <string> [string] ...<enter> '@
in either format, closing quotation mark must first character in line.
a here-string contains text between 2 hidden characters. in here-string, quotation marks interpreted literally. example:
@" help, type "get-help" "@
the output of command is:
help, type "get-help"
using here-string can simplify using string in command. example:
@" use quotation mark (') begin string. "@
the output of command is:
use quotation mark (') begin string.
in single-quoted here-strings, variables interpreted literally , reproduced exactly. example:
@' $profile variable contains path of windows powershell profile. '@
the output of command is:
$profile variable contains path of windows powershell profile.
in double-quoted here-strings, variables replaced values. example:
@" if have not created profile, path of profile file is: $profile. "@
the output of command is:
if have not created profile, path of profile file is: c:\users\user01\documents\windowspowershell\microsoft.powershell_profile.ps1.
here-strings typically used assign multiple lines variable. example, following here-string assigns page of xml $page variable.
$page = [xml] @" <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> format-table </command:name> <maml:description> <maml:para>formats output table.</maml:para> </maml:description> <command:verb>format</command:verb> <command:noun>table</command:noun> <dev:version></dev:version> </command:details> ... </command:command> "@
here-strings convenient format input convertfrom-stringdata cmdlet, converts here-strings hash tables. more information, see convertfrom-stringdata.
Comments
Post a Comment