Chinaunix

标题: 请大家来讲一下[[]] [打印本页]

作者: listen1001    时间: 2008-12-17 22:26
标题: 请大家来讲一下[[]]
看ABS时,看到[[]]时有点糊涂了请问一下他和[]的区别
另外请解释一下书里的这段代码

1 if echo "Next *if* is part of the comparison for the first *if*."
2
3 if [[ $comparison = "integer" ]]
4 then (( a < b ))
5 else
6 [[ $a < $b ]]
7 fi
8
9 then
10 echo '$a is less than $b'
11 fi
作者: walkerxk    时间: 2008-12-17 22:36
请查看man bash的[[ expression ]]部分
[]的话看看man test,很多功能一样,但是也有区别。
作者: biglazybug    时间: 2008-12-18 07:52
http://bbs.chinaunix.net/viewthread.php?tid=1310540
作者: 我是DBA    时间: 2008-12-18 09:31
原帖由 biglazybug 于 2008-12-18 07:52 发表
http://bbs.chinaunix.net/viewthread.php?tid=1310540

看了楼上的文章,大有所获
正在消化ing
作者: shaneqi    时间: 2008-12-18 09:50
有时候用[]会有错误,例如:
unexpected operator/operand
作者: shaneqi    时间: 2008-12-18 10:50
问一下,大家我以前有个程序,在[[ ]]中用-f 判断文件存在与否的时候经常会有unexpected operator/operand的错误,为什么呢?

if [[ -f file]]
then
fi
作者: walkerxk    时间: 2008-12-18 12:27
原帖由 shaneqi 于 2008-12-18 10:50 发表
问一下,大家我以前有个程序,在[[ ]]中用-f 判断文件存在与否的时候经常会有unexpected operator/operand的错误,为什么呢?

if [[ -f file]]
then
fi

if [[ -f file ]]
注意空格




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2