[wellylug] How do get Switch working in bash (Debian)
Jim Cheetham
jim at gonzul.net
Wed May 9 09:22:21 NZST 2007
On 09/05/07, Jim Cheetham <jim at gonzul.net> wrote:
> On 09/05/07, Sigurd Magnusson <sigurd at silverstripe.com> wrote:
> > Why does the following complain with
> > ./switchtest: line 5: syntax error near unexpected token `$colour'
> > ./switchtest: line 5: `switch ($colour)'
>
> Because "switch" isn't part of bash.
> IIRC it's part of csh.
Let's be a little more helpful :-)
bash uses the 'case ... esac' construct for this sort of thing.
case $colour in
red) echo "ruddy";;
green) echo "ecological";;
*) echo "odd";;
esac
I just installed a csh, and the 'switch' is in definately in there,
although the use of =~ is encouraged for pattern matching, so you
don't have to use switch at all.
if ($colour =~ red) then
echo "ruddy"
else if ($color =~ green) then
echo "ecological"
else
echo "odd"
endif
-jim
More information about the wellylug
mailing list