git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Allow shell scripts to run with non-Bash /bin/sh

From
Vineet Kumar <vineet@doorstop.net>
Date
Sep 22, 2007, 07:34 UTC
Message-ID
<20070922073446.GA3903@doorstop.net>
In-Reply-To
<7vd4wbgp9t.fsf@gitster.siamese.dyndns.org>
* Junio C Hamano (gitster@pobox.com) [070921 23:58]:
Show 30 quoted lines
> David Kastrup <dak@gnu.org> writes:
> 
> > Eygene Ryabinkin <rea-git@codelabs.ru> writes:
> >
> >>> That is, what does the shell say if you do this?
> >>> 
> >>> 	case Ultra in
> >>>         Super)
> >>>         	false ;;
> >>> 	Hyper)
> >>>         	true ;;
> >>> 	esac &&
> >>>         echo case returned ok
> >>
> >> It says 'case returned ok', so I will try to understand why it
> >> works here and does not work in the 'while' construct.
> >
> > What you actually need to do is
> >
> > false
> > case Ultra in
> >    Super)
> >    	false ;;
> > Hyper)
> >    	true ;;
> > esac && echo case returned ok
> 
> AHHHHHH.
> 
> Is "case" supposed to be transparent?

That doesn't seem to be the case (no pun intended) on either bash or dash. Here's what I tested on bash (apologies for the long lines; these are verbatim pastes from my shell):

vineet@sprocket:~$ false vineet@sprocket:~$ case Super in Super) echo super ; false ;; Hyper) echo hyper ; true ;; esac && echo case returned ok super vineet@sprocket:~$ false vineet@sprocket:~$ case Hyper in Super) echo super ; false ;; Hyper) echo hyper ; true ;; esac && echo case returned ok hyper case returned ok vineet@sprocket:~$ false vineet@sprocket:~$ case Ultra in Super) echo super ; false ;; Hyper) echo hyper ; true ;; esac && echo case returned ok case returned ok vineet@sprocket:~$

and on dash:

vineet@sprocket:~$ dash $ false $ case Super in Super) echo super ; false ;; Hyper) echo hyper ; true ;; esac && echo case returned ok super $ false $ case Hyper in Super) echo super ; false ;; Hyper) echo hyper ; true ;; esac && echo case returned ok hyper case returned ok $ false $ case Ultra in Super) echo super ; false ;; Hyper) echo hyper ; true ;; esac && echo case returned ok case returned ok $

So it seems like a "case" statement isn't special; it returns a status like any other statement.

Vineet
-- 
http://www.doorstop.net/
Previous: Junio C HamanoNext: David Kastrup
Message 11 of 45 in “Allow shell scripts to run with non-Bash /bin/sh”
  1. Allow shell scripts to run with non-Bash /bin/shEygene Ryabinkin, Sep 21, 2007
  2. Junio C HamanoSep 21, 2007
  3. David KastrupSep 22, 2007
  4. Junio C HamanoSep 22, 2007
  5. Junio C HamanoSep 22, 2007
  6. David KastrupSep 22, 2007
  7. Junio C HamanoSep 22, 2007
  8. Eygene RyabinkinSep 22, 2007
  9. David KastrupSep 22, 2007
  10. Junio C HamanoSep 22, 2007
  11. Vineet KumarSep 22, 2007
  12. David KastrupSep 22, 2007
  13. Junio C HamanoSep 22, 2007
  14. Adam FlottSep 22, 2007
  15. Junio C HamanoSep 22, 2007
  16. Eygene RyabinkinSep 23, 2007
  17. David KastrupSep 23, 2007
  18. Junio C HamanoSep 23, 2007
  19. David KastrupSep 23, 2007
  20. Supplant the "while case ... break ;; esac" idiomDavid Kastrup, Sep 23, 2007
  21. Junio C HamanoSep 23, 2007
  22. David KastrupSep 24, 2007
  23. David KastrupSep 24, 2007
  24. Junio C HamanoSep 24, 2007
  25. David KastrupSep 25, 2007
  26. Junio C HamanoSep 25, 2007
  27. Johannes SchindelinSep 25, 2007
  28. Avi KivitySep 25, 2007
  29. Mike HommeySep 24, 2007
  30. David KastrupSep 24, 2007
  31. David SymondsSep 24, 2007
  32. David KastrupSep 24, 2007
  33. Pierre HabouzitSep 24, 2007
  34. Pierre HabouzitSep 24, 2007
  35. Johannes SchindelinSep 24, 2007
  36. Miles BaderSep 24, 2007
  37. Eygene RyabinkinSep 24, 2007
  38. Miles BaderSep 24, 2007
  39. David KastrupSep 24, 2007
  40. Johannes SchindelinSep 24, 2007
  41. David KastrupSep 24, 2007
  42. Miles BaderSep 24, 2007
  43. Junio C HamanoSep 24, 2007
  44. David KastrupSep 24, 2007
  45. David KastrupSep 24, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.