[ale] Baffled on doing CASE statement with a Variable list of values

Neal Rhodes neal at mnopltd.com
Mon Aug 3 13:56:23 EDT 2015


Yes, that is another way of approaching if a case statement cannot be
made to work.    We're talking about a potentially large number of hits
on this script in an hour, so forking off a grep or fgrep seems like
something we'd prefer to avoid. 

I was just puzzled by the case not working for more than one value. 


On Mon, 2015-08-03 at 12:46 -0400, Ed Cashin wrote:
> I bet you only get the cases evaluated during the script's parsing.  I
> haven't checked that, though.
> 
> 
> 
> I think this would be a better place for using grep, not case.  Using
> "-F" has the additional advantage that you turn off globbing and
> regular expressions, since you seem to want to match fixed strings
> exactly.
> 
> 
> 
> $ cat /tmp/allowed
> 
> one
> 
> two
> 
> three
> 
> $ if echo two | grep -Ff /tmp/allowed > /dev/null 2>&1; then echo
> match; fi
> 
> match
> 
> $ 
> 
> 
> 
> 
> On Mon, Aug 3, 2015 at 12:03 PM, Neal Rhodes <neal at mnopltd.com> wrote:
> 
>         Exactly how does not assign a list of values separated by pipe
>         to use that variable later on in a script and make a CASE
>         statement happy? 
>         The script below shows a variety of attempts. 
>         
>         Ultimately, we're aiming to grab the list from a file, eg
>         "LIST="`cat allow.list`"
>         
>         
>         
>                 REMOTE_ADDR=one
>                 
>                 case $REMOTE_ADDR in
>                         one|two|three) echo "I like $REMOTE_ADDR" ;;
>                 # Picks this one.
>                         *) echo "I do NOT like $REMOTE_ADDR" ;;
>                 esac
>                 
>                 LIST="one|two|three"
>                 case $REMOTE_ADDR in
>                         $LIST) echo "But now I like $REMOTE_ADDR" ;;
>                         *) echo "But now I do NOT like
>                 $REMOTE_ADDR" ;; # Picks this one.
>                 esac
>                 
>                 case $REMOTE_ADDR in
>                         "$LIST") echo "And I like $REMOTE_ADDR" ;;
>                         *) echo "And I do NOT like $REMOTE_ADDR" ;;
>                 # Picks this one.
>                 esac
>                 
>                 LIST="one"
>                 case $REMOTE_ADDR in
>                         "$LIST") echo "Yet I like $REMOTE_ADDR" ;;
>                 # Picks this one.
>                         *) echo "Yet I do NOT like $REMOTE_ADDR" ;;
>                 esac
>                 
>                 LIST="one\|two\|three"
>                 case $REMOTE_ADDR in
>                         $LIST) echo "However now I like
>                 $REMOTE_ADDR" ;;
>                         *) echo "However now I do NOT like
>                 $REMOTE_ADDR" ;;     # Picks this one.
>                 esac
>         
>         
>         
>         
>         
>         _______________________________________________
>         Ale mailing list
>         Ale at ale.org
>         http://mail.ale.org/mailman/listinfo/ale
>         See JOBS, ANNOUNCE and SCHOOLS lists at
>         http://mail.ale.org/mailman/listinfo
>         
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
>   Ed Cashin <ecashin at noserose.net>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20150803/3b7454b1/attachment.html>


More information about the Ale mailing list