我知道這可以查看函式的內容:
cat function:\mkdir
很好,所以我想我會使用batto 語法突出顯示該輸出
PS C:\> bat function:\mkdir
function:\mkdir: No such file or directory
我認為這可能有效:
PS C:\> bat $(function:\mkdir)
function:\mkdir : The term 'function:\mkdir' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:7
bat $(function:\mkdir)
~~~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (function:\mkdir:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
這也失敗了:
cat function:\mkdir | bat
我究竟做錯了什么; 如何使用我選擇的決議器輸出函式內容?
在某些情況下,這是針對我的函式,它盡可能多地告訴我有關任何 cmdlet、函式、別名、模塊、外部腳本、應用程式或變數的資訊,只需指向what任何物件,它就會告訴您有關該物件的資訊(例如what mkdir或what what等)。如果bat在路徑上,它將使用它并將輸出著色為 PowerShell,如果不是,它將使用Get-Content. https://gist.github.com/roysubs/20c1bc888383d56df67008f4ba4179cb
uj5u.com熱心網友回復:
使用命名空間變數表示法:
# As argument.
bat $function:mkdir
# Via the pipeline
$function:mkdir | bat
筆記:
如果函式名包含特殊字符,如
-,則將整個識別符號括在 中{...},如${function:Get-Foo}.作為旁白:
- 如前所述,在Windows 上的 PowerShell 中,
cat是Get-Content. 相比之下,在類 Unix平臺上的 PowerShell 中,cat指的是標準 Unix 實用程式 (/bin/cat)。
- 如前所述,在Windows 上的 PowerShell 中,
簡而言之:
$function:mkdir相當于Get-Content function:mkdir- 有關詳細資訊,請參閱此答案。
結果是一個實體,當您將它傳遞給外部程式
[scriptblock]時,它被隱式字串化,例如在您的情況下。bat- 一個腳本塊可以方便地字串化到它的逐字內容,即它的源代碼。(在腳本塊文字
{ ... }的情況下 -不包括and{)。}
- 一個腳本塊可以方便地字串化到它的逐字內容,即它的源代碼。(在腳本塊文字
命名空間變數表示法僅適用于文字函式名稱;
Get-Content如果必須通過變數或運算式提供函式,請使用等效項:$cmd = 'mkdir' # As argument. bat (Get-Content function:$cmd) # Via the pipeline (Get-Content function:$cmd) | bat
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/532037.html
標籤:电源外壳功能解析
