shell报错:[[Tue: command not found
错误
写shell脚本时,在条件判断时遇到了如下报错
Tue Apr 14 13:39:10 CST 2020
/Users/Desktop/1.shell: line 3: [[Tue: command not found
/Users/Desktop/1.shell: line 6: [[Tue: command not found
3
脚本如下:
currentTime=$(date)
echo $currentTime
if [[$currentTime =~ "13"]];
then
echo 1
elif [[$currentTime =~ "14"]];
then
echo 2
else
echo 3
fi
原因
shell条件判断,在”[[“和”]]“与条件语句之间需要有空格。
因此,脚本修改成:
currentTime=$(date)
echo $currentTime
if [[ $currentTime =~ "13" ]];
then
echo 1
elif [[$currentTime =~ "14" ]];
then
echo 2
else
echo 3
fi
执行:
Tue Apr 14 13:39:08 CST 2020
1
问题解决,属于语法编写错误。
还没有评论,来说两句吧...