Shell script parameter check

To check if your script was given any command like parameters when run use scripts similar to the following,

in BASH use:
if [ $# -ne 2 ]
then
echo “Error in $0 – Invalid Argument Count”
echo “Syntax: $0 input_file output_file”
exit
fi

is CSH use:
if( $#argv < 2 ) then
echo “Usage: pltrps filename start_rpnum [ rpnum_inc END_rpnum]”
exit 1
endif

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s