if,elif,else语句在Bash中发布 [英] if, elif, else statement issues in Bash

查看:145
本文介绍了if,elif,else语句在Bash中发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法解决以下 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


推荐答案

elif 之间缺少空格[

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 ]
# ^ ^          ^

意思是<括号周围需要强>空格。否则,它将无法正常工作。这是因为 [本身命令。

这篇关于if,elif,else语句在Bash中发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆