Wikia

How To Wiki

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

1,794pages on
this wiki
Talk0

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.

Around Wikia's network

Random Wiki