目录名中的空格导致错误
您好,我有许多目录的名称中包含空格。我有一些脚本要在它们上运行。 这是一个示例脚本
#!/bin/bash
docid='/home/deel/PDF/rant/spr 2008 Shree rose Visheshank'
p=1
while [ $p -lt 117 ]; do
cp $docid/$p.pdf ./
p=$p+1
done
执行上述脚本后,我收到以下错误
cp: cannot stat `/home/deel/PDF/rant/spr': No such file or directory
cp: cannot stat `2008': No such file or directory
cp: cannot stat `Shree': No such file or directory
cp: cannot stat `rose': No such file or directory
cp: cannot stat `Visheshank/1.pdf': No such file or directory
./d2.sh: line 5: [: 1+1: integer expression expected
我尝试使用双引号“”,但结果是相同的。 我应该做什么改变?
Hi I have many directories which have blank space in their names.I have some scripts to be run on them.
Here is an example script
#!/bin/bash
docid='/home/deel/PDF/rant/spr 2008 Shree rose Visheshank'
p=1
while [ $p -lt 117 ]; do
cp $docid/$p.pdf ./
p=$p+1
done
Upon executing the above script I get following errors
cp: cannot stat `/home/deel/PDF/rant/spr': No such file or directory
cp: cannot stat `2008': No such file or directory
cp: cannot stat `Shree': No such file or directory
cp: cannot stat `rose': No such file or directory
cp: cannot stat `Visheshank/1.pdf': No such file or directory
./d2.sh: line 5: [: 1+1: integer expression expected
I have tried using double quotes "" but the results are same.
What changes should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这一行:
应为:
示例:
算术如下:
示例:
This line:
should read:
Example:
And arithmetic goes like:
Example:
您需要用双引号引用包含空格的名称。此外,
p=$p+1
并没有达到您的预期。这是更正后的循环:You need to quote the name containing spaces with double quotes. Moreover,
p=$p+1
does not do what you expect. Here is the corrected loop: