+-
![linux-使用[!时,在Bash的IF-ELSE条件下找不到命令! -d“ $DIR”] linux-使用[!时,在Bash的IF-ELSE条件下找不到命令! -d“ $DIR”]](/img/no_img.png)
我有这样的代码
#!/bin/bash
DIR="test_dir/";
if [! -d "$DIR"]; then
# If it doesn't create it
mkdir $DIR
fi
但是为什么执行它给了我这个:
./mycode.sh: line 16: [!: command not found
什么是正确的方法?
最佳答案
在[和!之间添加空格.以及[]之前也是如此.
#!/bin/bash
DIR="test_dir/";
if [ ! -d "$DIR" ]; then
# If it doesn't create it
mkdir $DIR
fi
引用变量也是一个好主意:
mkdir "$DIR"
点击查看更多相关文章
转载注明原文:linux-使用[!时,在Bash的IF-ELSE条件下找不到命令! -d“ $DIR”] - 乐贴网