[ale] Baffled on doing CASE statement with a Variable list of values
Lightner, Jeff
JLightner at dsservices.com
Mon Aug 3 13:56:32 EDT 2015
You sent this before the email I just sent that talks about while loop?
From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of Neal Rhodes
Sent: Monday, August 03, 2015 1:54 PM
To: Atlanta Linux Enthusiasts
Subject: Re: [ale] Baffled on doing CASE statement with a Variable list of values
Perhaps I didn't make it clear enough. Yes, the first approach of hard coding case values works.
All the other approaches of trying to put the values in a variable do not work.
On Mon, 2015-08-03 at 12:33 -0400, Jim Kinney wrote:
This works:
#!/bin/bash
FRED='one'
case $FRED in
one|two|pie) echo "got ${FRED}"; ;;
*) echo "crud"; ;;
esac
On Mon, 2015-08-03 at 12:03 -0400, Neal Rhodes 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<mailto:Ale at ale.org>
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
--
James P. Kinney III
Every time you stop a school, you will have to build a jail. What you
gain at one end you lose at the other. It's like feeding a dog on his
own tail. It won't fatten the dog.
- Speech 11/23/1900 Mark Twain
http://heretothereideas.blogspot.com/
_______________________________________________
Ale mailing list
Ale at ale.org<mailto:Ale at ale.org>
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20150803/487c78fa/attachment.html>
More information about the Ale
mailing list