bash脚本 - 如果,elif的,else语句问题 [英] Bash script - if, elif, else Statement Issues
问题描述
更多的问题与bash脚本我怕!
More problems with the bash script I'm afraid!
我似乎无法找出什么用if语句是在问候了ELIF,然后将下面的问题。请记住的printf
仍处于开发阶段我只是还没有能够在声明中还没有测试它这样极有可能错了。
I can't seem to work out what the issue with the following if statement is in regards to the elif and then. Keep in mind the printf
is still under development I just haven't been able to test it yet in the statement so is more than likely wrong.
我得到的错误是:
./timezone_string.sh: line 14: syntax error near unexpected token `then'
./timezone_string.sh: line 14: `then'
和语句是像这样。
if [ "$seconds" -eq 0 ];then
$timezone_string="Z"
elif[ "$seconds" -gt 0 ]
then
$timezone_string=`printf "%02d:%02d" $seconds/3600 ($seconds/60)%60`
else
echo "Unknown parameter"
fi
任何帮助将大大AP preciated
推荐答案
有一个空格 ELIF
之间缺少和 [
:
There is an space missing between elif
and [
:
elif[ "$seconds" -gt 0 ]
应
elif [ "$seconds" -gt 0 ]
当我看到这个问题是获得了很多的意见,重要的是要表明,语法,遵循的是:
As I see this question is getting a lot of views, it is important to indicate that the syntax to follow is:
if [ conditions ]
^ ^ ^
这意味着周围的括号,你总是必须有空格。否则,将无法正常工作。
meaning that around the brackets you always have to have spaces. Otherwise, it won't work.
这篇关于bash脚本 - 如果,elif的,else语句问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!