在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不,不是'@'這是詢問'@'''''''@'對。 –