Dynamic case statement in bash

Posted by infra.user on Stack Overflow See other posts from Stack Overflow or by infra.user
Published on 2011-01-14T03:28:54Z Indexed on 2011/01/14 3:53 UTC
Read the original article Hit count: 356

Filed under:
|
|

Hi folks,

I'm trying to figure out how to create a dynamic case statement in a bash script.

For example, let's say I have the output of an awk statement with the following contents

red
green
blue

In this scenario, the output can change at any time.

I'm trying to then execute different logic if a value is included in this awk output.

So if the data above is in $list, then I'd conceptually like to do something like:

case "${my_var}" in
    $list)
        .....
    something_else)
        .....
esac

I'm trying to use this to build a dynamic custom tab completion function (see http://www.debian-administration.org/article/An_introduction_to_bash_completion_part_2 for some background).

Any ideas?

Thanks.

© Stack Overflow or respective owner

Related posts about bash

Related posts about scripting