传递带有空格的计算路径 [英] Passing calculated paths with spaces

查看:89
本文介绍了传递带有空格的计算路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里尝试的是非常简单的操作,但无法弄清楚我要去哪里.我发现了许多其他有用的讨论-特别是在这里-但没有找到适合我的特定情况的任何东西.

I'm trying something really simple here, but can't figure out where I'm going wrong. I've found many other useful discussions of this - particularly here - but haven't found anything that covers my specific scenario.

在powershell中,我输入了以下内容:

In powershell, I have typed the following:

$path = "c:\program files\"
$path2 = "c:\program files\fred2\"
echoargs $path $path2
echoargs "$path" "$path2"

在两次对echoargs的调用中,我都得到了

In both calls to echoargs, I get

Arg 0 is <c:\program files" c:\program>
Arg 1 is <files\fred2">

返回

作为结果.如何获得正确传递的参数?

back as the result. How can I get the parameters to be passed through correctly?

NB:在我的真实脚本中,路径变量是由一些配置参数构成的,因此我不能仅将它们直接用单引号引起来.

NB: In my real script the path variables are built up from a few config parameters, so I can't just pass them directly in single quotes.

推荐答案

您需要在执行范围内用单引号将结果字符串引起来:

You need to enclose your result strings in single quotes inside the scope of the execution:

echoargs "'$path'" "'$path2'"

这会将它们传递给在单引号内定界的被调用应用程序,但是由于整个字符串仍在双引号中,因此您的参数将正确展开.

This will pass them to the called application delimited inside single quotes, but since the entire string is still in double quotes your parameter will be expanded correctly.

这篇关于传递带有空格的计算路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆