[How To] Check for Null/Empty parameter in a Shell Script

[Unix] Check for Null/Empty parameter in a hell script

 Many a times we wish to write generic shell scripts which have optional parameter, ie. They can run with or without parameters. In such cases, we need to check whether or not the user has supplied the parameter of not.

As discussed in my earlier posts, user defined shell variables range from $1,$2 etc.. The below trick can be used to check whether or not the user supplied the value for parameter.

if [ -z $1 ];  #Checks if the parameter value is not supplied.