bash中[test]和[[test]]有什么区别?
什么时候比另一个更合适?最后;
做什么?
if [[ -z $DIRECTORY ]];
then
DIRECTORY=html
fi
if [ ! -d "$DIRECTORY" ]; then
echo installation directory "'${DIRECTORY}'" does not exist
exit 1
fi
答案 0 :(得分:3)
[[
是一个类似于[
命令(但功能更强大)的bash关键字。请参阅http://mywiki.wooledge.org/BashFAQ/031和http://mywiki.wooledge.org/BashGuide/TestsAndConditionals除非您是为POSIX sh撰写内容,否则我们建议使用[[
。
答案 1 :(得分:0)
我们通常使用单方括号:
if [ -L $file ]; then
if [ $a -lt $b ]; then
" "
并将特殊字符视为正常字符(例如星号):if [ -z "$string" ]; then
当我们:
时,我们通常会加上方括号if [[ "$string1" == *[sS]tring* ]]; then
if [[ -a *.sh ]]; then
if [[ $a == 3 || $b == 4]]; then
" "
答案 2 :(得分:0)
[
适用于shell,[[
适用于bash。
例如:
试试[ $A -eq 1 ]
:如果未设置$A
,则会引发错误
[[ $A -eq 1 ]]
将有效。