我新学习shell脚本!我尝试了下面的代码,但我有错误
第15行:意外标记`elif
附近的语法错误
#!/bin/bash
read -p "Enter the number : " n
if [ $n -eq 1 ]
then
echo "$n is equal to 1 true"
elif [ $n -lt 4 ]
then
echo "$n is less than value of 4 ture"
else
echo "$n is not less then value of 4 false"
elif [ $n -gt 10 ]
then
echo "$n is greater than the value of 10 true"
else
echo "$n is not greater than the value of 10 false"
if [ $n -ge 0 ]
then
echo "$n is greater than or equal to 0"
else
echo "$n is not greater than or equal to 0"
fi
else
"Bye"
fi
有人可以帮忙吗?
答案 0 :(得分:1)
要说出你的意图有点难。正确的答案取决于你想在这里做什么。我的猜测是你想要这个:
if [ $n -eq 1 ]
then
echo "$n is equal to 1 true"
elif [ $n -lt 4 ]
then
echo "$n is less than value of 4 true"
elif [ $n -gt 10 ]
then
echo "$n is greater than the value of 10 true"
elif [ $n -ge 0 ]
then
# This will be true if $n is >= 4 and <= 10
echo "$n is greater than or equal to 0"
else
# Negative
"Bye"
fi