shell脚本if判断时报[: missing ]

源代码:

if [ -d "test"]
then
        echo dir named test exsited!
elif [ ! -d "test"];then
        mkdir test
        cd test
fi

报错:

[: missing ]

原因在于if判断在" ] "前面没有加空格,加上空格后就行了。

if [ -d "test" ]
then
        echo dir named test exsited!
elif [ ! -d "test" ];then
        mkdir test
        cd test
fi

 

posted @ 2021-08-13 16:48  CrazyJhq  阅读(305)  评论(0编辑  收藏  举报