Passing help options to a bash script I used this code to give -h(help) options to my bash script. It's working fine and I wanted to get the code reviewed.

while true; do
        if [ "$1" != "-l" ] &amp;&amp; [ "$1" != "-a" ] &amp;&amp; [ "$1" != "-h" ] &amp;&amp; [ "$1" != "" ];
        then
                output=$(curl -k -s -u "$username:$password" -H "X-Requested-With: Curl" -d "action=list&amp;echo_request=1" "${!url}" | grep -B 2 -w $name | grep ID | head -1 | sed 's/[^0-9]*//g')
        fi
        case "$1" in
                "")
                        echo "use -h for usage information";;
                -h)
                        echo  "-a       add"
                        echo  "-d       delete"
                        echo  "-l       name all"
                        echo  "-sv      addvlan"
                        echo  "-mv      add multiple vlan"
                        echo  "-dv      del vlan"
                        echo  "-ar      add route"
                        echo  "-mr      add multiple route"
                        echo  "-dr      delete route";;
                -a)
                        add ;;
                -d)
                        delete ;;
                -l)
                        list ;;
                -sv)
                        addvlan ;;
                -mr)
                        multipleroute ;;
                -dv)
                        delvlan "$@" ;;
                -mv)
                        addmulvlan ;;
                -dv)
                        delvlan ;;
                -ar)
                        addroute ;;
                -dr)
                        delroute "$@" ;;
        esac
        break
done;
There is a break statement at the end of the while true.
Like this, the while loop is completely pointless, you can remove it.

The output variable is never used.
Either you forgot to include the rest of the script,
or this is a pointless statement and should be removed.

The line that sets the output variable to the result of $(curl ...) is extremely long, and hard to read. It would be better to add some line breaks to reduce horizontal scrolling to read the code.
The grep-grep-head-sed chain can be shorter too with a little Awk magic.

This long condition would be simpler to write with a case:


if [ "$1" != "-l" ] &amp;&amp; [ "$1" != "-a" ] &amp;&amp; [ "$1" != "-h" ] &amp;&amp; [ "$1" != "" ]; then
    output=$(curl ...)
fi



Like this:

case "$1" in
    -l|-a|-h|"") ;;
    *)
        output=$(curl ...)
        ;;
esac