BASH Not in case

Hey guys, I'm trying to figure out a reasonable way to make a NOT clause in a case. The reason I do this is transcoding when the job is done, otherwise if I hit avi, there is no reason to turn it into avi again, I can just move it to the side (this is what the range should do at the core of my case ) Anyway, I have a protocode that I wrote like that, gives the essence of what I'm trying to do.

#!/bin/bash
for i in $(seq 1 3); do 

    echo "trying: $i"

    case $i in
        ! 1)    echo "1" ;;     # echo 1 if we aren't 1
        ! 2)    echo "2" ;;     # echo 2 if we aren't 2
        ! 3)    echo "3" ;;     # echo 3 if we aren't 3
        [1-3]*) echo "! $i" ;;  # echo 1-3 if we are 1-3
    esac

    echo -e "\n"

done

expected results will be something like this

2 3 ! 1
1 3 ! 2
1 2 ! 3

Help evaluate, thanks.

+4
source share
2 answers

case, . ( -, 3 1, 2), case . if.

[[ $i = 1 ]] || echo "1"
[[ $i = 2 ]] || echo "2"
[[ $i = 3 ]] || echo "3"
[[ $i = [1-3]* ]] && echo "! $i"

, " "; , *).

+6

extglob.

$ shopt -s extglob
$ case foo in !(bar)) echo hi;; esac
hi
$ case foo in !(foo)) echo hi;; esac
$
+2

Source: https://habr.com/ru/post/1527988/


All Articles