【发布时间】:2015-07-03 20:38:00
【问题描述】:
这里是shell脚本代码,当我在centos 6.6中使用时,它会得到两个错误信息......
./script12.bash: line 11: syntax error near unexpected token `$1'
./script12.bash: line 11: `case $1 in'
你能帮我找出错误吗?
#! /bin/bash
num=0
until [ "$num" -eq 30 ]
do
echo -n "Please input a number here : "
read num
if [ "$num" -gt 30 ] ; then
echo "$num" is too big , try again.
echo
elif [ "$num" -eq 30 ] ; then
echo BINGO !! you got it.
else
echo "$num" is too small , try again.
echo
fi
done
【问题讨论】:
-
尝试运行脚本,将第 11 行更改为
echo "BINGO !! you got it"。!!似乎被评估为历史扩展,尽管该功能应该在非交互式外壳中关闭。您可能以某种方式打开了它,但进行建议的编辑应该有助于确定是否是这种情况。 -
错误信息是指
case $1 in这行,在你发布的代码中不存在。错误来自其他地方。此外,您的 shebang 行中不应该有空格(应该是#!/bin/bash)。 -
@Jordan:这个空间很好(只要是正常的 ascii 空间)