Article View: gnu.bash.bug
Article #966case bug
From: Jun Hamano
Date: Sat, 26 Dec 1992 06:28
Date: Sat, 26 Dec 1992 06:28
67 lines
2538 bytes
2538 bytes
Earlier I reported an incompatibility with pattern list in `case'
command. Here is a fix. A patch is attached to the end of this
message.
The problem::
/bin/sh does not consider `abc' matches the pattern,
while bash 1.12 does, in the following script.
bash$ cat casebug.sh
__='
'
case abc in
*$__*) echo "The string abc has an newline in it." ;;
esac
bash$
The cause::
When executing a case command, bash expands each pattern
in pattern lists and then splits it into word-lists. In the
above example, *$__* is split into "*", and "*", because a
newline character resulting from $__ is part of $IFS. Pattern
matching in execute_case_command is done with only the first word
of the list, in this case the first "*", which resulted in a
(false) match. Bourne shell doesn't seem to split the result of
word expansion here.
The fix::
In the patch attached below, I replaced a call to
expand_word() with expand_word_no_split(). This does the same
set of substitution as expand_word does, but the result of the
substitution is not split.
-- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 --
bash$ rcsdiff -u3 execute_cmd.c
===================================================================
RCS file: execute_cmd.c,v
retrieving revision 1.1
diff -u3 -r1.1 execute_cmd.c
--- execute_cmd.c 1992/12/26 05:45:08 1.1
+++ execute_cmd.c 1992/12/26 05:56:08
@@ -66,7 +66,7 @@
extern pid_t last_made_pid;
#endif
-extern WORD_LIST *expand_words (), *expand_word ();
+extern WORD_LIST *expand_words (), *expand_word (), *expand_word_no_split ();
extern char *make_command_string ();
extern Function *find_shell_builtin (), *builtin_address ();
@@ -912,7 +912,7 @@
list = clauses->patterns;
while (list)
{
- WORD_LIST *es = expand_word (list->word, 0);
+ WORD_LIST *es = expand_word_no_split (list->word, 0);
char *pattern = (es) ? es->word->word : "";
if (fnmatch (pattern, word, FNM_NOESCAPE) != FNM_NOMATCH)
bash$
-- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 --
--
|
__-+-__ Jun Hamano
_-+ (|o|) +-_ junio@twinsun.com
! . !
Technical Details
Message-ID:
<bk6P}QH^@twinsun.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!junioShow Full Headers
Complete Article Headers
Newsgroups: gnu.bash.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!junio From: junio@twinsun.COM (Jun Hamano) Subject: case bug Message-ID: <bk6P}QH^@twinsun.com> Sender: gnulists@ai.mit.edu Organization: Twin Sun, Inc. (El Segundo CA) Distribution: gnu Date: Sat, 26 Dec 1992 06:28:52 GMT Approved: bug-bash@prep.ai.mit.edu Lines: 68