home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / bash / bug / 712 < prev    next >
Encoding:
Text File  |  1992-12-27  |  2.4 KB  |  81 lines

  1. Newsgroups: gnu.bash.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!twinsun.COM!junio
  3. From: junio@twinsun.COM (Jun Hamano)
  4. Subject: case bug
  5. Message-ID: <bk6P}QH^@twinsun.com>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: Twin Sun, Inc. (El Segundo CA)
  8. Distribution: gnu
  9. Date: Sat, 26 Dec 1992 06:28:52 GMT
  10. Approved: bug-bash@prep.ai.mit.edu
  11. Lines: 68
  12.  
  13. Earlier I reported an incompatibility with pattern list in `case'
  14. command.  Here is a fix.  A patch is attached to the end of this
  15. message.
  16.  
  17. The problem::
  18.     /bin/sh does not consider `abc' matches the pattern,
  19. while bash 1.12 does, in the following script.
  20.  
  21. bash$ cat casebug.sh
  22. __='
  23. '
  24. case abc in
  25. *$__*) echo "The string abc has an newline in it." ;;
  26. esac
  27. bash$ 
  28.  
  29. The cause::
  30.     When executing a case command, bash expands each pattern
  31. in pattern lists and then splits it into word-lists.  In the
  32. above example, *$__* is split into "*", and "*", because a
  33. newline character resulting from $__ is part of $IFS.  Pattern
  34. matching in execute_case_command is done with only the first word
  35. of the list, in this case the first "*", which resulted in a
  36. (false) match.  Bourne shell doesn't seem to split the result of
  37. word expansion here.
  38.  
  39. The fix::
  40.     In the patch attached below, I replaced a call to
  41. expand_word() with expand_word_no_split().  This does the same
  42. set of substitution as expand_word does, but the result of the
  43. substitution is not split.
  44.  
  45. -- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 --
  46.  
  47. bash$ rcsdiff -u3 execute_cmd.c
  48. ===================================================================
  49. RCS file: execute_cmd.c,v
  50. retrieving revision 1.1
  51. diff -u3 -r1.1 execute_cmd.c
  52. --- execute_cmd.c    1992/12/26 05:45:08    1.1
  53. +++ execute_cmd.c    1992/12/26 05:56:08
  54. @@ -66,7 +66,7 @@
  55.  extern pid_t last_made_pid;
  56.  #endif
  57.  
  58. -extern WORD_LIST *expand_words (), *expand_word ();
  59. +extern WORD_LIST *expand_words (), *expand_word (), *expand_word_no_split ();
  60.  extern char *make_command_string ();
  61.  
  62.  extern Function *find_shell_builtin (), *builtin_address ();
  63. @@ -912,7 +912,7 @@
  64.        list = clauses->patterns;
  65.        while (list)
  66.      {
  67. -      WORD_LIST *es = expand_word (list->word, 0);
  68. +      WORD_LIST *es = expand_word_no_split (list->word, 0);
  69.        char *pattern = (es) ? es->word->word : "";
  70.  
  71.        if (fnmatch (pattern, word, FNM_NOESCAPE) != FNM_NOMATCH)
  72. bash$ 
  73.  
  74. -- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 --
  75. --
  76.       |
  77.    __-+-__      Jun Hamano
  78. _-+ (|o|) +-_   junio@twinsun.com
  79.   !   .   !
  80.  
  81.