linux - Centos 6.6 shell 脚本 - 意外 token 附近出现语法错误

标签 linux bash shell centos

这是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

最佳答案

不知道怎么回事,但你的脚本包含奇怪的空白字符,十六进制编辑器显示 ASCII 代码 80 个字符,这似乎使 bash 感到困惑。当用普通空格(ASCII 代码 20)替换它们时,可以执行以下操作:

#!/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

关于linux - Centos 6.6 shell 脚本 - 意外 token 附近出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29861073/

相关文章:

bash - expr 和 if 在 bash 中

bash - 如何比较cpu串口是否正确

linux - 在 unix/linux 中删除文件中最后一次出现的字符串

linux - 使用 docker remove 获取权限被拒绝错误

linux - CMake 目标链接库 G++ 标志与 OSX Clang 冲突

c - 如何将 ELF 可执行文件转换为 C 代码?生成的 C 代码不需要是人类可读的

linux - 替换两列 linux

xml - 使用 incron 和 bash 脚本调用 REST API?

bash - 我怎么知道我是否在子 shell 中

mysql - 如何使用脚本shell执行mysql命令