gpt4 book ai didi

powershell - Powershell-变量未扩展

转载 作者:行者123 更新时间:2023-12-03 12:19:05 25 4
gpt4 key购买 nike

在某些服务器中,变量$cygwin_folder可以不同。但是由于某种原因,它并没有扩大。也许是由于斜线c:\$cygwin_folder造成的,但我不确定如何解决此问题?

c:\$cygwin_folder\bin\bash.exe -c some_command

这是代码:
if(test-path("c:\cygwin")) {
$cygwin_folder = "cygwin";
}
ElseIF (test-path("c:\cygwin64")) {
$cygwin_folder = "cygwin64";
}
Else {
echo "Cygwin directory not found";
exit
}

c:\$cygwin_folder\bin\bash.exe -c some_command

错误:
c:\$cygwin_folder\bin\bash.exe : The term 'c:\$cygwin_folder\bin\bash.exe' 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 C:\Program Files\zabbix\userparams\myscript.ps1:79 char:1
+ c:\$cygwin_folder\bin\bash.exe -c ("/usr/bin/scp -o StrictHostKeyChecking=no -o ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (c:\$cygwin_folder\bin\bash.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

最佳答案

隐式字符串扩展仅适用于参数参数,请使用&调用运算符将​​可扩展字符串作为命令来调用:

& "c:\$cygwin_folder\bin\bash.exe" -c some_command

关于powershell - Powershell-变量未扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61819091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com