checking the positional parameters

Hi all,

I have one small requirment...

I have prepared one script. we have to pass two possitional parameters to the script. What I want to do is if the parameters are not passed then i dont want the script to start the process...
For ex:

 
$ ./a.sh parm1 parm2
#Here, it can start the process as we passed 2 parameters..
$
 
$ ./a.sh parm1  (or)  $ ./a.sh 
#Here, it should not start the script process as we are not passed sufficient parameters..

Please advice some of your inputs here...

Thanks in advance...

Regards,
VRN

You can find the number of positional parameters using the special $# variable:

i.e.

if [ $# -ne 2 ]; then
  echo "Please pass two parameters..."
  exit
fi

thank you vm fo your reply..
but the script process will start here also to check the no. of parameters..
do we have any other way to not allow the script to run without parameters?

Thanks again..

Regards,
VRN

Sorry. Not sure I understand you.

You don't want to start the process (the script) at all if it doesn't have the correct number of arguments?

Either write a wrapper:

[ $# -eq 2 ] && ./MySccipt "$@"

Or... recompile the shell?!

You don't want to start the process (the script) at all if it doesn't have the correct number of arguments? --> yes Scott, i dont want to start the process of the script without parameters...

Why not?

If it doesn't have the correct # of arguments then it exits straight away. I don't see the problem with that.

Can you enlighten me?

Yes Scottn, even process started also, it'll immediately exit out from the script if we dont pass complete parameters.. I guess, it's enough for me.. let me give a try...

Thank you very much..

Great. I'm glad it's enough. It's the only way to stop it proceeding if it doesn't have the correct number of parameters.