Selective command line parameters.

Hi,

I have a script which has 3 command line parameters.But sometimes it will also take 2 command line parameters or 1.How to do it?

I am using $1,$2... to specify the command line parameters.

The script which i have written is given below.

#!/bin/sh
echo "database="$1
echo "parameter="$2
echo "table="$3
echo "1st parameter:$1"
echo "2nd parameter:$2"
echo "3rd parameter:$3"

The will not require all the 3 parameters to run each time.Sometimes it will take 2 and sometime 1 also.

Please suggest how to do it.

Thanks

You could just check the availability of each of them and assign it to other variables.

like,

 if [ "$1" != "" ]; then
echo "database=NO_OPTION_AVAILABLE"
else
echo "database="$1
fi

:slight_smile:

Thats ok.
But the problem is while executing the script.
suppose i do not want to pass parameter 1 and 2,need to pass only parameter 3.

How to do that?

if a mention only one then it will take it as the 1st parameter.:wall:

Similarly, you may have to pass another parameter which indicates what all parameters to select first! right??