ubuntu 虽然没有第16行,但仍然给出错误“第16行:语法错误:意外的行尾”[关闭]

bzzcjhmw  于 2024-01-06  发布在  其他
关注(0)|答案(2)|浏览(125)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受回答。

这个问题是由错字或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
23天前关闭
Improve this question

  1. a=10
  2. b=20
  3. c=30
  4. if [[ $a -gt $b && $a -gt $c ]]
  5. then
  6. echo "A is the greater number"
  7. if [[ $b -gt $a && $b -gt $c ]]
  8. then
  9. echo "B is the greater number"
  10. else
  11. echo "C is the greate number"
  12. fi

我试着做dos2unix化,添加另一个'fi',但仍然抛出相同的错误代码
Ed Morton编辑:这是你的代码,有常见的缩进:

  1. a=10
  2. b=20
  3. c=30
  4. if [[ $a -gt $b && $a -gt $c ]]
  5. then
  6. echo "A is the greater number"
  7. if [[ $b -gt $a && $b -gt $c ]]
  8. then
  9. echo "B is the greater number"
  10. else
  11. echo "C is the greate number"
  12. fi


我希望如果您以这种方式格式化代码,问题就不再是个谜了。

j0pj023g

j0pj023g1#

您有两个if语句,但只有一个fi。请尝试在第二种情况下使用elif

  1. a=10
  2. b=20
  3. c=30
  4. if [[ $a -gt $b && $a -gt $c ]]; then
  5. echo "A is the greater number"
  6. elif [[ $b -gt $a && $b -gt $c ]]; then
  7. echo "B is the greater number"
  8. else
  9. echo "C is the greater number"
  10. fi

字符串

ghhaqwfi

ghhaqwfi2#

更好的选择是将测试逻辑运算符拆分到括号外.
下面是你的代码的另一个实现的例子:

  1. a=10
  2. b=20
  3. c=30
  4. if [ "$a" -gt "$b" ] && [ "$a" -gt "$c" ]; then
  5. gtst='A'
  6. elif [ "$b" -gt "$a" ] && [ "$b" -gt "$c" ]; then
  7. gtst='B'
  8. else
  9. gtst='C'
  10. fi
  11. printf '%s is the greatest number.\n' "$gtst"

字符串

展开查看全部

相关问题