Fandom

How To Wiki

How to execute different code depending on the command line arguments in a bash script

1,795pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

command line arguments within a bash scripts


Example of a simple script:

#!/bin/bash

#apply a function with a parameter
function apply
{
    request=$1;
    echo "$request"
}

#the first argument
case $1 in 
    1)
        #1) first code
	apply "first"
	;;
    2)
        #2) second code
	apply "second"
	;;
    3)
        #3) third code
	apply "third"
	;;
    *)
	echo "bad argument"
	;;
esac


From HowTo Wiki, a Wikia wiki.

Also on Fandom

Random Wiki