switch in bash

Bash shell is the common linux command language.
Post Reply
mister_v
Posts: 167
Joined: Thu Mar 04, 2010 9:19 pm

switch in bash

Post by mister_v »

Hi,

is there an equivalent of switch in bash?

chris
Site Admin
Posts: 170
Joined: Mon Jul 21, 2008 9:52 am

Re: switch in bash

Post 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.

Post Reply