How To 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

Recommended Posts

Contact

604-309-8713
info@solidfoundationwebdev.com

Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected