所以我试图在bash脚本中执行if else if else语句。截至目前,当我运行此脚本时,我收到以下错误消息“./groupJobs.sh:line 76:意外令牌附近的语法错误elif'
./groupJobs.sh: line 76:
elif [$ jobsize -lt $ 2];然后'”
我已经在网上查看了多个示例,看不出我所做的和其他人说的有什么不同。
任何帮助将不胜感激。 (第76行是最后一个elif声明)
if [ $filesize -ge $2 ]; then
#goes this way if file is to big to put in a job with anyother files
$filename >> $jobname$jobnumber;
elif [ $jobsize -ge $2 ]; then
#job is done being created
elif [ $jobsize -lt $2 ]; then
#add file to job and move on to next file check
fi
答案 0 :(得分:4)
elif
块的正文不能为空(评论不算)。如果您只需要固定身体,请使用:
功能。
if [ $filesize -ge $2 ]; then
#goes this way if file is to big to put in a job with anyother files
$filename >> $jobname$jobnumber;
elif [ $jobsize -ge $2 ]; then
#job is done being created
:
elif [ $jobsize -lt $2 ]; then
#add file to job and move on to next file check
:
fi
答案 1 :(得分:3)
elif
语句需要一个实际的陈述。暂时将echo "job creation done"
和echo "add file to job"
放在那些陈述(或其他任何你想要的东西)中......
if [ $filesize -ge $2 ]; then
#goes this way if file is to big to put in a job with anyother files
$filename >> $jobname$jobnumber;
elif [ $jobsize -ge $2 ]; then
#job is done being created
echo "whatever you want"
#the above line just has to be some sort of actual statement
elif [ $jobsize -lt $2 ]; then
#add file to job and move on to next file check
echo "whatever you want"
#the above line just has to be some sort of actual statement
fi
答案 2 :(得分:1)
Bash需要if / elif块中的命令(例如echo
)。评论不计算在内。