[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Despite text in gnu bash manual, quote removal appears to be performed o
From: |
Stahlman Family |
Subject: |
Despite text in gnu bash manual, quote removal appears to be performed on case pattern |
Date: |
Sun, 10 Dec 2006 09:11:44 -0600 |
Mingw (Msys) Bash 2.04.0(1)-release
Microsoft Windows XP Home Edition Version 2002 Service Pack 2
Perhaps I'm misunderstanding something, but the way I read the manual text on the case command, if anything is printed in the
example below, it would be "2", since if the quotes around " foo bar " are not removed in the case pattern, then the first case is
testing the string
<space>foo<space>bar<space>
against
<double-quote><space>foo<space>bar<space><double-quote>
Actually, it is not clear to me whether the 2nd case should match (it does), since backslash removal is also considered quote
removal. However, the section on pattern matching explicitly states that the "escaping backslash is discarded when matching" so
perhaps there is no inconsistency there...
$ case $dbg in
" foo bar ") echo "1" ;;
\ foo\ bar\ ) echo "2" ;;
esac
1
It's not that the current behavior doesn't make sense (since most people would expect to be able to quote the case pattern to
inhibit glob matching), but it doesn't seem consistent with the man page. Specifically, from the Bash(1) manpage distributed with
cygwin Bash 3.00...
---------- BEGIN EXCERPT FROM MANUAL
case
The syntax of the case command is:
case word in [ [(] pattern [| pattern]...) command-list ;;]... esac
case will selectively execute the command-list corresponding to the first pattern that matches word. The `|' is used to separate
multiple patterns, and the `)' operator terminates a pattern list. A list of patterns and an associated command-list is known as a
clause. Each clause must be terminated with `;;'. The word undergoes tilde expansion, parameter expansion, command substitution,
arithmetic expansion, and quote removal before matching is attempted. Each pattern undergoes tilde expansion, parameter expansion,
command substitution, and arithmetic expansion.
---------- END EXCERPT FROM MANUAL
Note that quote removal is conspicuously omitted from the list of operations performed on pattern. Interestingly, when I look at
other Bash man pages online, I see something different; specifically...
case word in [ ( pattern [ | pattern ]
A case command first expands word, and tries to match it against each pattern in turn, using the same matching rules as for pathname
expansion (see Pathname Expansion below)....
The behavior I'm seeing seems consistent with this explanation of the case command, since the rules for pathname expansion do not
prohibit quote removal. Which of these specifications is correct?
Thanks,
Brett S.
- Despite text in gnu bash manual, quote removal appears to be performed on case pattern,
Stahlman Family <=