求助,关于shell中的空格问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
love_ai88
帖子: 79
注册时间: 2010-05-27 10:26

求助,关于shell中的空格问题

#1

帖子 love_ai88 » 2010-05-28 17:21

初学shell,在wiki上看到的例子,不知道啥原因,望高手赐教

a.sh就是该代码存在的shell文件

if [ -x"~/Workspace/shell/a.sh" ];then
echo true
else
echo false
fi
打印true

if [ -x "~/Workspace/shell/a.sh" ];then
echo true
else
echo false
fi
打印false

只是-x后面的空格问题,为啥,谢谢~~
Acer Aspire 4738G
i5,6370M,2G,500G
Ubuntu 11.04
aerofox
帖子: 1453
注册时间: 2008-05-24 8:30

Re: 求助,关于shell中的空格问题

#2

帖子 aerofox » 2010-05-29 23:34

因为只有 -x 后有空格才表示紧跟其后的字符串是否指向一个可执行的文件名,否则就成了测试 -x"~/Workspace/shell/a.sh" 这个字符串是不是空。
love_ai88
帖子: 79
注册时间: 2010-05-27 10:26

Re: 求助,关于shell中的空格问题

#3

帖子 love_ai88 » 2010-05-31 20:37

哦,原来如此,谢谢~~
Acer Aspire 4738G
i5,6370M,2G,500G
Ubuntu 11.04
回复