在PowerShell中,很少有程序以@'
开头并以'@
结尾,但是当我键入@'
并在PowerShell提示符下按回车时,它会引发错误。任何人都可以解释我该如何解决这个问题?什么是@参数?
什么是@参数?
回答
@'
和'@
标记Here-String的开始和结束。键入@'
然后按在PowerShell控制台输入通常应该给你续行提示符(>>
):
PS C:>@'
>> _
如果你得到你最有可能没有键入单(或双)报价错误,但是有前向或反向或某种印刷报价。如果这是你应该得到的“无法识别的记号”的错误这样的案例:
PS C:\>@´
At line:1 char:1
+ @´
+ ~
Unrecognized token in source text.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnrecognizedToken
@'...'@
和@"..."@
是“这里字符串”(在about_quoting_rules记录):的
HERE-STRINGS
The quotation rules for here-strings are slightly different.
A here-string is a single-quoted or double-quoted string in which quotation marks are interpreted literally. A here-string can span multiple lines. All the lines in a here-string are interpreted as strings even though they are not enclosed in quotation marks.
Like regular strings, variables are replaced by their values in double-quoted here-strings. In single-quoted here-strings, variables are not replaced by their values.
You can use here-strings for any text, but they are particularly useful for the following kinds of text:
-- Text that contains literal quotation marks -- Multiple lines of text, such as the text in an HTML or XML document -- The Help text for a script or function
A here-string can have either of the following formats, where represents the linefeed or newline hidden character that is added when you press the ENTER key.
Double-quotes:
@"<Enter> <string> [string] ...<Enter> "@
Single-quotes:
@'<Enter> <string> [string] ...<Enter> '@
In either format, the closing quotation mark must be the first character in the line.
A here-string contains all the text between the two hidden characters. In the here-string, all quotation marks are interpreted literally. For example:
@" For help, type "get-help" "@
The output of this command is:
For help, type "get-help"
Using a here-string can simplify using a string in a command. For example:
@" Use a quotation mark (') to begin a string. "@
The output of this command is:
Use a quotation mark (') to begin a string.
In single-quoted here-strings, variables are interpreted literally and reproduced exactly. For example:
@' The $profile variable contains the path of your Windows PowerShell profile. '@
The output of this command is:
The $profile variable contains the path of your Windows PowerShell profile.
In double-quoted here-strings, variables are replaced by their values. For example:
@" Even if you have not created a profile, the path of the profile file is: $profile. "@
The output of this command is:
Even if you have not created a profile, the path of the profile file is: C:\Users\User01\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1.
Here-strings are typically used to assign multiple lines to a variable. For example, the following here-string assigns a page of XML to the $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 the output as a 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 are also a convenient format for input to the ConvertFrom-StringData cmdlet, which converts here-strings to hash tables. For more information, see ConvertFrom-StringData.
- 1. 函数参数是什么?
- 2. 参数中的3个点是什么?/什么是可变参数(...)参数?
- 3. ON_LBN_SELCHANGE的参数是什么?
- 4. ns是什么参数?
- 5. 什么是父参数?
- 6. addTouchEventListener的参数是什么
- 7. Renderscript,`in`参数是什么?
- 8. 什么是(0,somefunc)(参数)
- 9. 什么是关系参数?
- 10. phpMyAdmin:什么是参数null?
- 11. 什么是“。”参数在PHP?
- 12. 什么是参数值?
- 13. 什么是overwritting参数
- 14. C++类参数是什么?
- 15. 什么是Twilio URL参数?
- 16. 什么是sysctl()的参数?
- 17. survfit.coxph:什么是newdata参数?
- 18. 什么是参数化?
- 19. 什么是“struct file_operations”参数?
- 20. 什么是我的参数[]?
- 21. Parcel.readStringArray()的参数是什么?
- 22. 什么是ximgproc_DisparityWLSFilter.filter()参数?
- 23. 什么是(void *的)参数
- 24. graphics setColor - 参数是什么?
- 25. map.setCenter的参数是什么?
- 26. 什么是toString参数?
- 27. sem_init(...):什么是pshared参数?
- 28. OpenCV:WarpPerspective函数的参数是什么?
- 29. 什么是current_user_can()函数参数?
- 30. beforeSend jquery函数的参数是什么?
可能重复[什么在Powershell中使用“@”符号?](http://stackoverflow.com/questions/363884/what-does-the-symbol-do-in-powershell) – elssar
在PowerShell中自己键入'@''不应该给你一个错误。它应该让你继续提示('>>')。 –
@elssar不,不是'@'这是询问'@'''''''@'对。 –