user2771729
user2771729

Reputation: 458

error near unexpected token 'elif'

I'm getting the error:

ex02.sh: line 6: syntax error near unexpected token `elif'
ex02.sh: line 6: `elif [ #$ -gt 1 ] ; then'

My script:

#!/bin/bash

if [ #$ -le 1 ] ; then
        echo 'usage: ex02.sh max|min|sum v2 [v2 ...]'
        exit 1
elif [ #$ -gt 1 ] ; then
        if [ "$1" = "min" ] || [ "$1" = "max" ] || [ $1 = "sum" ]; then
                echo "ERROR: invalid command: $1"
                exit 2
        fi
fi

I've looked online and most of the answers seem to say its due to carriage returns being saved in the file. I created this using vi and set line breaks to unix. What is wrong?

Upvotes: 0

Views: 129

Answers (1)

Manuel Barbe
Manuel Barbe

Reputation: 2164

You should use "$#" instead of #$

Upvotes: 1

Related Questions