Cygwin中的Windows批处理在路径和参数中带有空格 [英] Windows batches in Cygwin with spaces in path and arguments
本文介绍了Cygwin中的Windows批处理在路径和参数中带有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑以下虚拟Windows批处理脚本:
Consider this dummy Windows batch script:
echo %1
假定只是将终端的 first 参数回显到终端.
假设其路径分别为. Windows的Cygwin风格是:
Supposed just to echo to the terminal its first argument.
Assume its path in resp. Windows, Cygwin style is:
c:\test\win.bat
/cygdrive/c/test/win.bat
来自Cygwin bash:
From Cygwin bash:
$ c:\test\win.bat "hello world"
"hello world"
因此引号正确地标识了一个参数.
So quotes correctly identify a single argument.
但是现在让我们在路径中引入空格:
But now let us introduce spaces in path:
"c:\te st\win.bat"
/cygdrive/c/te\ st/win.bat
然后:
$ /cygdrive/c/te\ st/win.bat "hello world"
赠予:
"C:\te" is not recognized as an internal or external command, operable program or batch file.
以下情况同样发生:
$ "/cygdrive/c/te st/win.bat" "hello world"
应注意以下几点:
$ /cygdrive/c/te\ st/win.bat "hello"
hello
即hello
现在被传递给win.bat
而不加引号(或者使用"/cygdrive/c/te st/win.bat" "hello"
).
That is hello
is now passed to win.bat
unquoted (and with "/cygdrive/c/te st/win.bat" "hello"
either).
如何在路径和参数中都留空格?
How can I have spaces both in the path and the argument?
推荐答案
$ echo "echo %~1" > /cygdrive/c/te\ st/win.bat
$ cat /cygdrive/c/te\ st/win.bat
echo %~1
$ cmd /c $(echo "c:\te st\win.bat"| sed 's/ /^ /g') "aaa bbb"
C:\Users\Me>echo aaa bbb
aaa bbb
这篇关于Cygwin中的Windows批处理在路径和参数中带有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文