Bash脚本 – if,elif,else语句问题

前端之家收集整理的这篇文章主要介绍了Bash脚本 – if,elif,else语句问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > How do I compare two string variables in an ‘if’ statement in Bash?11个答案更多的问题与bash脚本恐怕!

我似乎无法解决什么问题与以下if语句是关于elif然后。记住printf仍在开发中,我只是还没有能够在语句中测试它,所以很可能是错误的。

我得到的错误是:

./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

任何帮助将不胜感激

elif和[:]之间缺少一个空格:
elif[ "$seconds" -gt 0 ]

应该

elif [ "$seconds" -gt 0 ]

因为我看到这个问题是得到了很多意见,重要的是要指出的语法遵循是:

if [ conditions ]
  ^ ^          ^

意思是在括号周围总是有空格。否则,它将不工作。

原文链接:https://www.f2er.com/bash/391399.html

猜你在找的Bash相关文章