|
|
使用"[]"简写test时注意 |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
在Shell中,“[]“是高频使用词,可是如果不留神,也会频频带来运行错误。 在使用"[]"简写test时注意:左中括号后和右中括号前的空格是必须的,否则如: for file in `ls` do if [-f $file ]; then echo $file is file fi; done
运行错误为: [-f: not found
如果: for file in `ls` do if [ -f $file]; then echo $file is file fi; done 则: test: ] missing
因为如果前后没有空格,Shell不能辨别表达式何时开始,何时结束。
|
|
相关文章:相关软件: |
|