Skip to content

问题解答

问题一:[[: not found

使用sh命令执行脚本test.sh

$ cat test.sh 
#!/bin/bash

NAME="asdf asdf as"

if [[ ${NAME} == as* ]]
then
    echo "匹配"
else
    echo "不匹配"
fi

得到问题如下:

$ sh test.sh 
test.sh: 5: test.sh: [[: not found
不匹配

原因是相比较于bash而言,dash的功能少,无法解析[[ ]],使用bash执行即可

$ bash test.sh 
匹配