Create Optional Arguments In Bash Function Or Script

Posted By Weston Ganger

If you need an optional parameter for a bash function or script heres how to add them.

myprint(){
 CURRENT_APPNAME=${1-appname};
 NEW_APPNAME=${2-new_${CURRENT_APPNAME}};

 echo $CURRENT_APPNAME; # appname
 echo $NEW_APPNAME; #new_appname
}

Related External Links:

Article Topic:Software Development - Linux

Date:October 06, 2016