[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: case $var in $list) issue
From: |
#!microsuxx |
Subject: |
Re: case $var in $list) issue |
Date: |
Fri, 1 Nov 2024 16:44:39 +0100 |
On Fri, Nov 1, 2024, 16:20 Zachary Santer <zsanter@gmail.com> wrote:
> On Thu, Oct 31, 2024 at 9:55 PM #!microsuxx <fxmbsw7@gmail.com> wrote:
> >
> > ~ $ echo $short
> > li|la|ds|fs|ac|U|S|u|s|r|i|f|c
>
> declare -a short=( li la ds fs ac U S u s r i f c )
> match='false'
> for pattern in "${short[@]}"; do
> if [[ ${whatever} == ${pattern} ]]; then
> match='true'
> break
> fi
> done
>
> Probably the way to go if your list of patterns is determined dynamically.
>
sorry i dont want loops ( cause slow and more code )
i did .. [[ ${arr[$1]} ]] check
the other possibility is to use
match='@(a|b|..)' instead of just match='a|b|
.'
If the case construct didn't require a | between different patterns in
> the same pattern list, then you could just expand ${short[@]} there.
>
> array=( zero one two three four )
> case one in
> ( "${array[@]}" )
> printf 'nope one\n'
> ;;&
> ( "${array[*]}" )
> printf 'nope two\n'
> ;;&
> ( ${array[@]} )
> printf 'nope three\n'
> ;;&
> ( ${array[*]} )
> printf 'nope four\n'
> ;;
> esac
>
> Not sure what bash is trying to do with the quoted "${array[@]}" expansion
> here:
>
> case 'zero one two three four' in
> ( "${array[@]}" )
> printf 'nope five\n'
> ;;&
> ( "${array[*]}" )
> printf 'yep six\n'
> ;;&
> ( ${array[@]} )
> printf 'yep seven\n'
> ;;&
> ( ${array[*]} )
> printf 'yep eight\n'
> ;;&
> esac
>
> yep six
> yep seven
> yep eight
>
> Using [[ ]] in a for loop is going to be easier to wrap your head
> around, especially if you've got whitespace and special pattern
> matching characters - *, ?, [...] - which you want to do their
> pattern-matching thing.
>
i dont get what ur trying there ..
i do IFS=sep and arr[*] to fastly ( i suppose join the elements for further
use )
ah okk u did try in one
i didnt cause i use new ifs and also reset it afterwards
u can try
shopt -s extglob
m=a\|b s=b
case $s in @($m)) echo ye .. ;;
*) echo bla ;;
esac
>
- Re: case $var in $list) issue, Zachary Santer, 2024/11/01
- Re: case $var in $list) issue,
#!microsuxx <=
- Re: case $var in $list) issue, Greg Wooledge, 2024/11/01
- Re: case $var in $list) issue, Zachary Santer, 2024/11/01
- Re: case $var in $list) issue, #!microsuxx, 2024/11/01
- Re: case $var in $list) issue, Zachary Santer, 2024/11/01
- Re: case $var in $list) issue, #!microsuxx, 2024/11/01
- Re: case $var in $list) issue, #!microsuxx, 2024/11/01
- Re: case $var in $list) issue, Zachary Santer, 2024/11/01
- Re: case $var in $list) issue, #!microsuxx, 2024/11/01