[Top][All Lists]

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

Bash aliases erroneously expanded in 'case' patterns in some conditions

From: Torka Noda
Subject: Bash aliases erroneously expanded in 'case' patterns in some conditions
Date: Sat, 25 Mar 2017 04:34:46 +0100

Configuration Information [Automatically generated, do not
change]: Machine: x86_64
OS: linux-gnu
Compiler: x86_64-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale'
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I. -I./include -I.
-I./include -I./lib
-march=ivybridge -O2 -pipe -Wno-parentheses
-Wno-format-security uname output: Linux localhost 4.1.x-gentoo
#1 SMP PREEMPT Sun Mar 12 05:04:06 CET 2017 x86_64 Intel(R)
Core(TM) i7-3770 CPU @ 3.40GHz GenuineIntel GNU/Linux Machine
Type: x86_64-pc-linux-gnu

Bash Version: 4.4
Patch Level: 12
Release Status: release

        When sourcing a script (rather than executing it), if
        the "in" keyword of a case construct is on its own line
        (rather than on the first line of the construct with
        "case", or on the same line as the first pattern), then
        the pattern is expanded as an alias, if it exists.

        Thus the word will be checked silently against the
        expanded alias, and likely fail, which is unexpected.

        If the alias contains a space (command argument), then
        Bash will fail with the following error message:

        bash: foo2.sh: line 9: syntax error near unexpected
        token `words'
        bash: foo2.sh: line 9: `two words '


        # ====================

        alias foo='oneword'
        # Fails silently to match 'foo':
        case "$foo_word"
                foo) echo 'Test 1!';;

        # ====================

        alias foo='two words'
        # Errors out:
        case "$foo_word"
                foo) echo 'Test 2!';;

        # ====================

        Source these scripts with `source` (it happens in my
        ~/.bashrc too).

        If you comment the alias line (and run `unalias foo`
        from your shell, to clear the alias), then both scripts
        will work without issue.


reply via email to

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