How can I write something like:
if $1 = a thencheck second statementif $2 is b then echo a and belse $1 = 1 thencheck second statementif $2 = 2 then echo 1 and 2
...where all of the variables are strings?
This is what I have:
fun() {
if [ "$1" == "a" ]; # when $1 is a then
then
if [ "$2" == "" ]; # $1 is a and $2 is empty string
echo a
elif [ "$2" == "b" ]; # $1 is a and $2 is b
then
echo "a and b"
fi
fi
else
if [ "$1" == "1" ]; # when $1 is 1 then
then
if [ "$2" == "" ]; # $1 is 1 and $2 is empty string
echo a
elif [ "$2" == "2" ]; #$1 is 1 and $2 is 2
then
echo "1 and 2"
fi
fi
}
casestatement could help you: stackoverflow.com/questions/1477518/nested-case-in-bash-scriptcasein Bash (switchin C-like languages). Follow @eckes' link (that comment should be the (accepted) answer) IMHO.