在 GNU/Linux 中,我会这样做:
PROGPATH=/long/and/complicated/path/to/some/bin
$PROGPATH/program args...
但是在Powershell中,如果我尝试这样做:
$PROGPATH=\long\and\complicated\path\to\some\bin
$PROGPATH\program args...
我得到:
At script.ps1:2 char:...
+ $PROGPATH\program args ...
+ ~~~~~~~~
Unexpected token '\program' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
那么我如何在 bash 中,在 Powershell 中做我知道如何做的简单事情?
最佳答案
使用调用运算符“&”。 https://ss64.com/ps/call.html
相关:Executing a command stored in a variable from PowerShell
$progpath = 'c:\windows\system32'
& $progpath\notepad somefile.txt
有空格的东西:
& 'C:\Program Files\internet explorer\iexplore' yahoo.com
其他选项,添加到路径:
$env:path += ';C:\Program Files\internet explorer'
iexplore yahoo.com
并反引号空格:
C:\Program` Files\internet` explorer\iexplore yahoo.com
关于powershell - 如何在 Powershell 中执行相当于 $PROGPATH/program 的 bash?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57677186/