Differences between revisions 1 and 2
Revision 1 as of 2007-05-03 00:00:48
Size: 191
Editor: redondos
Comment:
Revision 2 as of 2007-05-24 14:21:15
Size: 323
Editor: redondos
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
== I want to check if [[ $var == foo || $var == bar || $var = more ]] without repeating $var n times. == == I want to check if [[ $var == foo || $var == bar || $var == more ]] without repeating $var n times. ==
Line 4: Line 4:
Here's a portable solution:
Line 9: Line 10:

And here's one that uses '[[':
{{{
   if [[ $var =~ foo|bar|more ]]; then
      ...
   fi
}}}

Anchor(faq66)

I want to check if [[ $var == foo || $var == bar || $var == more ]] without repeating $var n times.

Here's a portable solution:

   case $var in
      foo|bar|more) ... ;;
   esac

And here's one that uses '[[':

   if [[ $var =~ foo|bar|more ]]; then
      ...
   fi

BashFAQ/066 (last edited 2015-06-20 07:58:04 by ormaaj)