bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

case statement: wrong behaviour of the ";;&" operator


From: Norman Krebs
Subject: case statement: wrong behaviour of the ";;&" operator
Date: Sat, 26 Jan 2019 06:30:05 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

Configuration Information:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
uname output: Linux hpxz 4.9.37 #1 SMP Sat Jul 15 08:39:05 CEST 2017 x86_64 
GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 2
Release Status: release

Description:

    "echo x" shouldn't be executed here, but it gets:

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

    Following the man page, the ';;&' operator should cause testing the _next_
    pattern: '2)' only and not _all_ following patterns.

    The bash manpage says:

    "
    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.
    "


Repeat-By:
    Use the ';;&' in a case statement which contains a second matching pattern 
list, p.e.:

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

    will print 'y' - while '*1*)' is not the next pattern list after '1)'.


-- 
/Kind regards, Norman

--------------------------------------------------------------------
   Norman Krebs               +49 (0)5333 946930
   Nordweg 3                 +49 (0)160 90768856
   D-38173 Hachum/Evessen
   EMail:  address@hidden
------------------------------------------http://www.kohnos.net-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]