1

I'm trying to compile this code but I am getting the following error:

Q2.sh: line 18: syntax error near unexpected token `fi'
Q2.sh: line 18: `fi'

at line 15, I'm trying to verify if the parameter numero is bigger than 0. Any help is appreciated

Thanks

#!bin/bash

numero=$1

if test $# -eq 0; then
    echo "Argument Manquants"
    exit 1
fi

if ! [[ "$numero" =~ ^[0-9]+$ ]] ; then
    exec >&2; echo "Le parametre doit etre un digit";
    exit 1
fi

if [ $numero -le 0 ]
$$  echo "Le parametre doit etre plus grand que 0"  
    exit 1
fi

cat /etc/passwd grep "$numero"
4

3 回答 3

4

您忘记了条款; then中的部分if

if [ "$numero" -le 0 ]; then
    ...
fi
于 2013-05-22T16:46:51.260 回答
1

看起来您错过了then末尾的声明if,并且您只使用了单个方括号。尝试为此替换该块:

if [[ $numero -le 0 ]]; then
    echo "Le parametre doit etre plus grand que 0"  
    exit 1
fi
于 2013-05-22T16:48:23.437 回答
0

当我将在 Windows 上编辑的脚本复制到 unix 系统时,我遇到了类似的问题。在首次亮相时,我得到了同样的错误。

当我在目标 m/c 上的编辑器中编辑文件一次时,脚本运行没有问题。

对我来说,这似乎是字符编码问题。但在我的情况下,我仍在寻找克服它的解决方案。

可能有点帮助。

于 2014-04-03T09:50:44.133 回答