Configuration Information [Automatically generated, do not change]: Machine: i686 OS: linux-gnu Compiler: i686-pc-linux-gnu-gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -msse3 -O2 -march=athlon64 -pipe uname output: Linux strythbox 2.6.24.3 #2 Thu Mar 13 10:21:15 EDT 2008 i686 AMD Athlon(tm) 64 Processor 3800+ AuthenticAMD GNU/Linux Machine Type: i686-pc-linux-gnu
Bash Version: 3.2 Patch Level: 39 Release Status: release Description: the gnu bash manual indicates: "The syntax of the case command is: case word in [ [(] pattern [| pattern]...) command-list ;;]... esac" and further that: "Each pattern undergoes tilde expansion, parameter expansion, command substitution, and arithmetic expansion." While command substitution and parameter expansion occur, the resulting strings are not parsed in a fashion consistent with the normal behavior. Take, for example, the string "1|2". when used in the form case 2 in \ 1|2) ... the function execute_case_command, in the strmatch line. This line is executed twice, once being a strmatch (2,1) and the other being strmatch (2,2). Obviously the 2,2 is the match. On the other hand, when a variable VAR='1|2' is used (case 2 in $var ... ) the comparison performed is strmatch (2,1|2) which fails. 1|2 is never broken into its components. Repeat-By: #! /bin/bash VAR='1|2' echo test is 'case 2 in $VAR=1|2' case 2 in $VAR) echo good ;; *) echo fail ;; esac echo echo test is 'case 2 in 1|2' case 2 in 1|2) echo good ;; *) echo fail ;; esac echo VAR='2' echo test is 'case 2 in $VAR=2' case 2 in $VAR) echo good ;; *) echo fail ;; esac echo echo test is 'case 2 in 2' case 2 in 2) echo good ;; *) echo fail ;; esac echo echo test is "case 2 in \`echo '1|2'\`" case 2 in `echo '1|2'`) echo good ;; *) echo fail ;; esac echo echo test is 'case 2 in 1|2' case 2 in 1|2) echo good ;; *) echo fail ;; esac