Linux

How To Create Optional Arguments In Bash Function Or Script

Posted by Weston Ganger on October 06, 2016

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:


Posted in Linux and Tagged with bash 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts