Default values for the arguments to a Unix shell script?

Viewed 9924

Normally when a parameter is passed to a shell script, the value goes into ${1} for the first parameter, ${2} for the second, etc.

How can I set the default values for these parameters, so that if no parameter is passed to the script, we can use a default value for ${1}?

4 Answers

Perhaps I don't understand your question well, yet I would feel inclined to solve the problem in a less sophisticated manner:

                     ! [[ ${1} ]]   &&   declare $1="DEFAULT"

Hope that helps.

Related