bash – shell脚本中的整数表达式预期错误

前端之家收集整理的这篇文章主要介绍了bash – shell脚本中的整数表达式预期错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是一个 shell脚本的新手,所以我有一个问题.我在这段代码中做错了什么?
#!/bin/bash
echo " Write in your age: "
read age
if [ "$age" -le "7"] -o [ "$age" -ge " 65" ]
then
echo " You can walk in for free "
elif [ "$age" -gt "7"] -a [ "$age" -lt "65"]
then
echo " You have to pay for ticket "
fi

当我试图打开这个脚本时,它要求我的年龄,然后它说

./bilet.sh: line 6: [: 7]: integer expression expected
./bilet.sh: line 9: [: missing `]'

我不知道我做错了什么如果有人能告诉我如何解决这个问题,我会很感激,对不起我可怜的英语,我希望你们能够理解我.

您可以使用以下语法:
#!/bin/bash

echo " Write in your age: "
read age

if [[ "$age" -le 7 || "$age" -ge 65 ]] ; then
    echo " You can walk in for free "
elif [[ "$age" -gt 7 && "$age" -lt 65 ]] ; then
    echo " You have to pay for ticket "
fi
原文链接:https://www.f2er.com/bash/383988.html

猜你在找的Bash相关文章