How is the correct syntax for a more complex case statement?
2
votes
1
answer
312
views
case "$1","$name" in
-py | --python | --python3,*) if [[ "$name" =~ \..+$ ]]; then
That doesn't catch stuff, which actually it should,
like…
USERNAME@HOSTNAME:~$ myscript --python surfer
Funny thing:
Simplify the multi pattern conditional to…
--python,*) if [[ "$name" =~ \..+$ ]]; then
and it works!
With the bitterly-repetitive outlook to have to place that section 3 times: 1st for -py
, then for --python
, and finally for --python3
for catching all patterns.
But the other thing is - the other way around:
case "$1" in
-py | --python | --python3) if [[ ! "$name" =~ \.py$ ]]; then
That's fine, that works!
So, that disproves my assumption, that the multi pattern syntax might be incorrect,
might needs the spaces to be removed, or any kind of bracket around the sum of all 3 patterns to be interpreted as a group, where the first OR the second OR the third pattern is supposed to be catched.
And with all this I really have the impression, that you can't have both in
GNU bash, version 4.3, multi pattern AND aside of that conditional a second conditional like "$name". Could that be? Or have I made a mistake in trying to acchieve that?
Asked by futurewave
(213 rep)
Apr 4, 2024, 10:13 PM
Last activity: Apr 4, 2024, 11:11 PM
Last activity: Apr 4, 2024, 11:11 PM