[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
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
-DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin'
-DSYS_BASHRC='/etc/bash/bashrc'
-DSYS_BASH_LOGOUT='/etc/bash/bash_logout'
-DNON_INTERACTIVE_LOGIN_SHELLS -DSSH_SOURCE_BASHRC
-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
Description:
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 '
Repeat-By:
# ====================
#!/bin/bash
alias foo='oneword'
foo_word='foo'
#
# Fails silently to match 'foo':
#
case "$foo_word"
in
foo) echo 'Test 1!';;
esac
# ====================
#!/bin/bash
alias foo='two words'
foo_word='foo'
#
# Errors out:
#
case "$foo_word"
in
foo) echo 'Test 2!';;
esac
# ====================
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.
Thanks.
- Bash aliases erroneously expanded in 'case' patterns in some conditions,
Torka Noda <=