Command Line arguments to your shell script in linux

Passing command line arguments to shell scripts allow you to re-use a lot of scripts.  In shell scripts the command you execute is always the reserved variable of $0 each additional command is seperated by spaces.  So for example if you typed:

./max_it special cheese now

$0 = max_it

$1 = special

$2 = cheese

$3 = now

$n is the number of arguments passed on the command line starting with 0

When providing command line arguments it is best to providing some sanity checking:

if [ $n -nq 1 ]
        then
            echo "Usage : $0 IP_address 
            exit
        fi


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.