linux shell 中 如何处理空格的路径?

有目录如下:[root@iZ94611itifZtest]#find.-typed./ab#注中间有空格./ac有一个test.sh脚本如下:[root@iZ94611i... 有目录如下:
[root@iZ94611itifZ test]# find . -type d
./a b #注中间 有空格
./a c

有一个test.sh 脚本如下:
[root@iZ94611itifZ test]# cat test.sh
#/bin/bash

myhome=`pwd`
for str in `find . -type d`
do

if [ `expr index "$str" "#"` -eq 0 ]
then

cd "$str"
echo "process $str"
cd $myhome
fi
done

运行 [root@iZ94611itifZ test]# sh test.sh
process .
test.sh: line 10: cd: ./a: No such file or directory
process ./a
test.sh: line 10: cd: b: No such file or directory
process b
test.sh: line 10: cd: ./a: No such file or directory
process ./a
test.sh: line 10: cd: c: No such file or directory
process c

linux shell 中 如何处理空格的路径?
展开
 我来答
happygrid
2015-06-21 · TA获得超过3106个赞
知道大有可为答主
回答量:2672
采纳率:69%
帮助的人:2222万
展开全部
错在不能使用for 来获取目录,不信你可以在do里面执行 echo "$str"
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式