2

I tried to use the code below :

read choice
case $choice in 
"1")    less /var/log/messages
    if [$? -ne 0]; then 
        less /var/log/syslog
    fi
    ;;
etc
etc
etc
*) echo "Please enter a choice between 1 and 20";;
esac

when executing ./myScript.sh I got this :

./myScript.sh: line 4: [1: command not found

I can't find the problem !

4

2 回答 2

7

In your if statement, put space after [ and before ], as

if [ $? -ne 0 ]; then 
于 2013-10-20T08:43:39.813 回答
1

At (4, 8) and (4, 16) are the problems. Place a space between (4, 7) and (4, 8) and another space between (4, 15) and (4, 16). These ordered pairs are like (line, column).

Do it like this on line 4:

    if [ $? -ne 0 ]; then
于 2020-03-29T16:37:31.953 回答