Accepting command line arguments for bash scripts

Well, while I was scripting today, I learned how to accept command line arguments, and are as such

$ bash_scrip.sh var1 var2

$1 = var1 and $2 = var2 and to use those

if [ “$1” = “start” ]

then

## Do stuff

elif [ “$2” = “stop” ]

then

## do more stuff

else

## If it doesnt match anything

## Do more stuff

fi
Resources

How to read command line arguments in bash – http://how-to.wikia.com/wiki/How_to_read_command_line_arguments_in_a_bash_script

Cyberciti Bash Scripting Guide – http://bash.cyberciti.biz/guide/Main_Page

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s