[ale] Baffled on doing CASE statement with a Variable list of values
Ed Cashin
ecashin at noserose.net
Mon Aug 3 12:46:05 EDT 2015
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/cca62463/attachment.html>
More information about the Ale
mailing list