gpt4 book ai didi

powershell - 带括号的环境变量导致 “unexpected token”错误

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

我有一个PowerShell(2.0)脚本,该脚本在程序文件目录下运行可执行文件,并且我正在使用环境变量来引用路径:

Start-Process "$($env:ProgramFiles)\ProgramFolder\Executable.exe"

这在我的x86机器上工作正常,但是现在我试图在x64机器上运行它。由于可执行文件是32位的,因此它位于“C:\ Program Files(x86)”下,因此,我已如下调整脚本,因为我需要使用的环境变量是 ProgramFiles(x86):
Start-Process "$($env:ProgramFiles(x86))\ProgramFolder\Executable.exe"

我收到此错误:

Unexpected token '(' in expression or statement.



那么,考虑到包含括号的环境变量,我该如何引用呢?

最佳答案

在这种情况下,您不需要子表达式$():

"${env:ProgramFiles(x86)}\ProgramFolder\Executable.exe"

输出:
C:\Program Files (x86)\ProgramFolder\Executable.exe

如果仍要使用子表达式,则可以指定一个包含PowerShell语法字符的变量名称,如下所示:
"$(${env:ProgramFiles(x86)})\ProgramFolder\Executable.exe"

关于powershell - 带括号的环境变量导致 “unexpected token”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23611856/

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