Wrong case behaviour?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wrong case behaviour?
# 1  
Old 01-25-2019
Wrong case behaviour?

The following case statement should not execute the "echo x" in my opinion, but it does. I'm pondering if this is a bug and I should send a bug report or not. Tested in fully patched bash version 4.4 and 5.0

Code:
case "1" in
    1) : ;;&
    2) : ;;
    *) echo x ;;
esac

The man page says:

Quote:
...
case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esac
...
If the ;; operator is used, no subsequent matches are attempted after
the first pattern match. Using ;& in place of ;; causes execution to continue with
the list associated with the next set of patterns. Using ;;& in place of ;; causes
the shell to test the next pattern list in the statement, if any, and execute any
associated list on a successful match.
...
This User Gave Thanks to elbrand For This Post:
# 2  
Old 01-26-2019
I see absolutely no inconsistency in the behavior of the case statement you have shown us with ;;& as the pattern list terminator for the pattern 1 when the string given to the case statement matches both the pattern 1 and the pattern * given the quote you have shown us from the (presumably bash) man page.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 3  
Old 01-26-2019
But, following the man page, shouldn't the ;;& terminator test only the next pattern list 2) : ;; and not also *) echo x ;;?
# 4  
Old 01-26-2019
I find the wording in the man page you quoted ambiguous. The way you describe the code acting fits one of the possibilities of that ambiguous statement; and the way you expect it to behave fits another of the possibilities of that ambiguous statement.

I can't say that bash is behaving wrong from the quote you have shown us in the man page and I can't say that what you expected to happen is wrong. But, it appears that the way you want it to behave is not the way bash actually behaves.

I think it would be a good idea to post a bug report against the man page pointing out that the section you have quoted can be interpreted two ways and that bash does not behave the way you expected it to behave after reading the quoted text.
These 3 Users Gave Thanks to Don Cragun For This Post:
# 5  
Old 01-26-2019
Ok, I'm going to send a bug report. Thank you very much!
# 6  
Old 01-26-2019
Hi, elbrand
I do not see inconsistencies.
Code:
case "1" in
    1) echo 1;& #command in the next template even without a match
    2) echo 2;;& #next patten list comparison
    *) echo x
esac

But thanks a lot for the post. This is "case" behavior new to me.
This User Gave Thanks to nezabudka For This Post:
# 7  
Old 01-27-2019
Here the response to my bug report:

Quote:
Badly worded manual. What it means is "pretend this match didn't happen,
even though the command list has been executed, and continue scanning
the patterns in the case statement looking for another match, then do its
list, and after that, whatever its terminating operator says to do". But that
is quite a mouthfull ...
So the behaviour is as intended. ;;& means: continue to look for a matching pattern.
These 5 Users Gave Thanks to elbrand For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

2. Shell Programming and Scripting

Conversion from Upper Case to Lower Case Condition based

Hello Unix Gurus : It would be really appreciative if can find a solution for this . I have records in a file . I need to Capitalize the records based on condition . For Example i tried the following Command COMMAND --> fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
Discussion started by: tsbiju
12 Replies

3. Shell Programming and Scripting

Something is wrong with this switch( case statement.

I started writing a script to save the files from a camera I got the other day, which mounts in /Volumes , and I got into it and started building this menu. The only problem is that the switch case is coming up as a syntax error at the parenthesis after a case. Here is the code: while : do ... (2 Replies)
Discussion started by: snakemasterAK
2 Replies

4. Shell Programming and Scripting

[Solved] Change Upper case to Lower case in C shell

Is there a command that can switch a character variable from UPPER case to lower case? like foreach AC ( ABC BCD PLL QIO) set ac `COMMAND($AC)` ... end Thanks a lot! (3 Replies)
Discussion started by: rockytodd
3 Replies

5. Shell Programming and Scripting

sed ignoring case for search but respecting case for subtitute

Hi I want to make string substitution ignoring case for search but respecting case for subtitute. Ex changing all occurences of "original" in a file to "substitute": original becomes substitute Origninal becomes Substitute ORIGINAL becomes SUBSTITUTE I know this a little special but it's not... (1 Reply)
Discussion started by: kmchen
1 Replies

6. Shell Programming and Scripting

data array needs to change upper case to lower case

Hi all, i have a data array as followes. ARRAY=DFSG345GGG ARRAY=234FDFG090 ARRAY=VDFVGBGHH so on.......... i need all english letters to be change to lower case. So i am expecting to see ARRAY=dfsg345ggg ARRAY=234fdfg090 ARRAY=vdfvgbghh so on........ If i have to copy this data in... (8 Replies)
Discussion started by: usustarr
8 Replies

7. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies

8. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question