powershell中的双引号问题
我试图将安装参数传递给 powershell 中的变量,但这样做时出现错误。
$InstallString = "$InstallLocation\application.exe" /install / quiet CID="BsDdfi3kj" Tag="CinarCorp"
我尝试将其运行为输入“&”符号但它不起作用,我检查了很多网站但无法解决它。任何帮助将不胜感激。
谢谢..
I am trying to pass installation arguments to a variable in powershell but I get errors doing that.
$InstallString = "$InstallLocation\application.exe" /install / quiet CID="BsDdfi3kj" Tag="CinarCorp"
I tried to run this as putting "&" symbol but it didn't work and I checked many websites but I couldn't solve it. Any help will be appreciated.
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
=
右侧使用的语法仅在直接调用如下命令时才有效:请注意,在
quiet
之前有一个虚假的空格字符,我已将其删除。当您实际上想要将命令存储在变量中时,请像这样更改语法:
我已将整个字符串括在双引号内,并通过在内部双引号前面放置反引号来转义内部双引号。
您还可以使用 here-string 以避免转义内部双引号:
请注意,实际字符串以及最终的"@ 必须从线。如果您缩进实际的字符串,则变量中会包含空格/制表符,这通常是不需要的
修剪 如果您坚持缩进:
我建议阅读 关于引用规则了解更多详细信息。
The syntax used to the right of
=
only works when directly calling the command like this:Note that you had a spurious space character before
quiet
which I removed.Change the syntax like this when you actually want to store the command in a variable:
I have enclosed the whole string within double-quotes and escaped the inner double-quotes by placing a backtick in front of them.
You could also use a here-string to avoid having to escape the inner double-quotes:
Note that the actual string as well as the final
"@
have to start at the beginning of the line. If you indent the actual string, the spaces/tabs are included in the variable, which is usually not wanted.You could of course trim the string if you insist on indentation:
I recommend to read about Quoting Rules for further details.