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

Jim Kinney jkinney at jimkinney.us
Mon Aug 3 13:58:44 EDT 2015


Ah. Yeah. Getting the | to be read and not executed and then executed and not read will fail. 

Chunk it into an array and search without the case. 

Or grep.

On August 3, 2015 1:53:52 PM EDT, Neal Rhodes <neal at mnopltd.com> wrote:
>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
>> > 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
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>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

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20150803/709c1ef5/attachment.html>


More information about the Ale mailing list