Page 1 of 1

switch in bash

Posted: Sat Sep 19, 2020 2:21 pm
by mister_v
Hi,

is there an equivalent of switch in bash?

Re: switch in bash

Posted: Wed Sep 23, 2020 4:01 pm
by chris
Yes, it look lik this:

Code: Select all

#Set the IP
case $VALUE in
1)
IP=192.168.1.160
NAME='a';
;;
2)
IP=192.168.1.161
NAME='B';
;;
*)
IP=192.168.1.1
NAME='Default';
;;
esac
in this case $VALUE can be 1 or 2,
anything else will result in default.
I think it is a string compare, so you can use anything.