<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.32.2">
</HEAD>
<BODY>
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. <BR>
<BR>
I was just puzzled by the case not working for more than one value. <BR>
<BR>
<BR>
On Mon, 2015-08-03 at 12:46 -0400, Ed Cashin wrote:
<BLOCKQUOTE TYPE=CITE>
I bet you only get the cases evaluated during the script's parsing. I haven't checked that, though.
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BR>
<BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
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.
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BR>
<BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
$ cat /tmp/allowed<BR>
<BR>
one<BR>
<BR>
two<BR>
<BR>
three<BR>
<BR>
$ if echo two | grep -Ff /tmp/allowed > /dev/null 2>&1; then echo match; fi<BR>
<BR>
match<BR>
<BR>
$ <BR>
<BR>
<BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
On Mon, Aug 3, 2015 at 12:03 PM, Neal Rhodes <<A HREF="mailto:neal@mnopltd.com">neal@mnopltd.com</A>> wrote:
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
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? <BR>
The script below shows a variety of attempts. <BR>
<BR>
Ultimately, we're aiming to grab the list from a file, eg "LIST="`cat allow.list`"<BR>
<BR>
<BR>
<BLOCKQUOTE>
REMOTE_ADDR=one<BR>
<BR>
case $REMOTE_ADDR in<BR>
one|two|three) echo "I like $REMOTE_ADDR" ;; # Picks this one.<BR>
*) echo "I do NOT like $REMOTE_ADDR" ;;<BR>
esac<BR>
<BR>
LIST="one|two|three"<BR>
case $REMOTE_ADDR in<BR>
$LIST) echo "But now I like $REMOTE_ADDR" ;;<BR>
*) echo "But now I do NOT like $REMOTE_ADDR" ;; # Picks this one.<BR>
esac<BR>
<BR>
case $REMOTE_ADDR in<BR>
"$LIST") echo "And I like $REMOTE_ADDR" ;;<BR>
*) echo "And I do NOT like $REMOTE_ADDR" ;; # Picks this one.<BR>
esac<BR>
<BR>
LIST="one"<BR>
case $REMOTE_ADDR in<BR>
"$LIST") echo "Yet I like $REMOTE_ADDR" ;; # Picks this one.<BR>
*) echo "Yet I do NOT like $REMOTE_ADDR" ;;<BR>
esac<BR>
<BR>
LIST="one\|two\|three"<BR>
case $REMOTE_ADDR in<BR>
$LIST) echo "However now I like $REMOTE_ADDR" ;;<BR>
*) echo "However now I do NOT like $REMOTE_ADDR" ;; # Picks this one.<BR>
esac<BR>
</BLOCKQUOTE>
<BR>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BLOCKQUOTE>
<BR>
_______________________________________________<BR>
Ale mailing list<BR>
<A HREF="mailto:Ale@ale.org">Ale@ale.org</A><BR>
<A HREF="http://mail.ale.org/mailman/listinfo/ale">http://mail.ale.org/mailman/listinfo/ale</A><BR>
See JOBS, ANNOUNCE and SCHOOLS lists at<BR>
<A HREF="http://mail.ale.org/mailman/listinfo">http://mail.ale.org/mailman/listinfo</A><BR>
<BR>
</BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BR>
<BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<BR>
<BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
--
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
Ed Cashin <<A HREF="mailto:ecashin@noserose.net">ecashin@noserose.net</A>>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>