我正在尝试写一个像这样的表达式--->如果在bash中[ $condition1 ] && [ $condition2 ]
,但我一直都会遇到同样的错误
syntax error near unexpected token `elif'
./leer.sh: line 25: `elif [[ "$($(date +%Y) -eq $ano)" && "$($(date +%m) -lt $mes)" ]]'
代码的那部分是:
elif [[ $($(date +%Y) -eq $year) && $($(date +%m) -lt $month) ]]
then
echo "Well done";
答案 0 :(得分:1)
这里有一些问题:
if
开头,而是elif
fi
$(...)
你试着这样做吗?
#!/bin/bash
year=2013
month=11
if [[ $(date +%Y) -eq $year && $(date +%m) -lt $month ]]; then
echo "Well done"
fi