Web Hosting Talk







View Full Version : bash shell case statement


innova
08-15-2003, 12:32 PM
Hi,

I am trying to build a script and coming up against a stumbling block. I have a case statement that selects from #X options and carries out a function if the inputted variable matches...

The problem is, I wish to make my code modular, so I dont have to keep adding case statements for each additional thing.

I have a variable that stores a list of options that the script can take an action on.

I need to know how I can compare a single value against a list of values, and if so, call a given function.

For example:

if [ $variable == $list ]
then
variable_action
fi

Obviously this code doesnt work. I need to evaluate $list, get the list, and then check to see if the variable is in the list. If so, proceed with an install function. If not, log a useful error.

Hopelessly complicated :(

jb4mt
08-15-2003, 01:35 PM
You say you want to make your code modular....I don't think shell is the best tool. Can't you use Perl or Tcl or some other language that's almost certainly installed on *nix?