powershell - 如何在 Powershell 中执行相当于 $PROGPATH/program 的 bash?

标签 powershell syntax command-line-arguments

在 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/

相关文章:

python - Windows 上的 check_call 和命令行参数

powershell - 如何将参数传递给 Windows 计划任务?

powershell - 如何通过姓名或 SamAccountName 获取广告组成员

arrays - 从Powershell中的对象中删除一个或多个成员

haskell - 使用 NoImplicitPrelude 重新绑定(bind)数字文字的语法

haskell - 比较 Haskell 中通配符的相等性..?

c++ - 为什么不能将 *pointer+offset 用作左值? ("error: non-lvalue in assignment")

python - 将目录作为命令行参数传递给 python 脚本

powershell - 如何在 PowerShell v3 模块中可靠地引用外部 .NET 程序集?

c++ - MSVC++ 中源字符集编码规范,如 gcc "-finput-charset=CharSet"