This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Changed handling of "!" in /bin/sh?


On 15 Jan, Eric Blake wrote:
>  
>  According to Luke Kendall on 1/15/2007 7:39 PM:
> > I have a script that starts #!/bin/sh which has occasional things like
> > the use of an exclamation mark in a string, or a case statement to
> > accept an exclamation mark to throw a shell, which has stopped working
> > now that I've upgraded to a non-ancient Cygwin (i.e. now that sh ==
> > bash).
>  
>  Simple test case, please?

Here's one example (the script is called yorn):

#!/bin/sh
#
# yorn query: loops until y or n, returns for if
#
while true
do
    printf "$* (y, n, or !) ? " > /dev/tty
    read ans
    case "X$ans" in
      Xy*|XY*)
	exit 0
	;;
      Xn*|XN*)
	exit 1
	;;
      X!|Xsh)
	echo "Command level escape - hit CTRL-D when finished." > /dev/tty
	exec > /dev/tty 2>&1
	PS1='$$ ' sh -i
	echo
	;;
      *)
	echo "Please answer yes or no (or ! to temporarily escape to Unix):" > /dev/tty
	;;
    esac
done < /dev/tty

I also just wrote this which fails with a "line 2: !": event not found":

#!/bin/sh
echo "Hello world!"

> > It seems that /bin/sh is now trying to interpret "!" as bash would! 
> > How can I make /bin/sh work like a Bourne shell, globally?
>  
>  You can't.  Bourne shell is obsolete (unless you are on Solaris, and are a
>  die-hard to use their /bin/sh instead of /usr/xpg4/bin/sh), because it
>  lacks functions, ${} command substitution, and other useful features of
>  modern shells.  Rather, you can make /bin/sh behave like a POSIX shell -
>  you do that by invoking bash as /bin/sh instead of /bin/bash (ie. you are
>  ALREADY getting POSIX behavior).

POSIX behaviour would be close enough.  Note that the same script runs
okay under Linux, so I agree that by simply having the #!/bin/sh at the
start it should also work under Cygwin.

>  ash was slowly moving in this direction,
>  but had its own set of bugs.  If your legacy scripts don't behave properly
>  with /bin/sh, then most likely, it is a bug in your script according to
>  the rules of POSIX, that just happened to work with ash because of a
>  matching bug in ash.

Well, please see what you think from the example above.

> > The same script works fine if run by ash instead of bash, and it also
> > works fine under Linux (where sh is bash), so it seems like there's
> > some problem with bash's emulation of sh under Cygwin.
>  
>  That's a pretty harsh claim without a sample script to back it up.  I try
>  very hard to make Cygwin's /bin/sh exactly like Linux's /bin/sh.

Sorry, I didn't mean to sound harsh.  Please let me know if you need
any kind of cygcheck output.  FWIW:

SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:igncr:interactive-comments:monitor

Thanks, Eric.

Regards,

luke


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]