我是一个
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