This is the mail archive of the
mailing list for the Cygwin project.
Re: Changed handling of "!" in /bin/sh?
- From: Luke Kendall <luke dot kendall at cisra dot canon dot com dot au>
- To: cygwin <cygwin at cygwin dot com>
- Date: Tue, 16 Jan 2007 15:34:07 +1100 (EST)
- Subject: Re: Changed handling of "!" in /bin/sh?
On 15 Jan, Eric Blake wrote:
> > SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:igncr:interactive-comments:monitor
> There you go. You have "history" enabled in SHELLOPTS, which is a
> non-POSIX extension, and explains why /bin/sh is not doing what you
> expected. Your shell scripts are inheriting interactive behavior, and
> trying to do history expansion when they encounter !.
Ah! I'm not setting that - it comes "for free". :-)
Any idea how to turn it off? I grepped in /etc/* and /etc/profile.d/*
for SHELLOPTS but didn't find it. In the System Env Vars in Windows I
define SHELLOPTS to be igncr (only). If I echo %SHELLOPTS% in a
cmd.exe window it's set to igncr only. What's defining the other
things? It's a readonly env variable, isn't it? I.e. I don't think I
can correct it from within a bash shell?
We are working in a heterogeneous environment, and use CVS for source
code (and script) management, so that's why we want to allow CR/LF in
> I still hope to
> find time to getting around and trying to teach bash which options in
> SHELLOPTS should be ignored when starting a non-interactive session. In
> the meantime, I would recommend turning history off, or at least changing
> the history expansion character, if you absolutely must set SHELLOPTS.
Well, I think we have to use it to define igncr. And all bash users
who use it for interactive shells would expect to have a history, yes!
Are the extra options being turned on automatically only for
interactive shells? Do you mean that if I want POSIX behaviour from
shell scripts then I can't have history for interactive shells?
> And if all else fails, and you are still running scripts with history
> enabled, then according to bash documentation, the only way to bypass the
> history character is to quote it, but that in double quotes, "\!"
> preserves the \, so you have to write something like:
> echo "Hello world"\!
Sure, I know. Doing that for 200 scripts will be a pain, especially
since they will then execute with literal "\!"s when the same scripts
are run from Linux. As in (yes, I just tried):
Perhaps a simple workaround is to replace /bin/sh with /bin/ash?
I'm puzzled that others haven't found the same problem, so I still
suspect there must be something unusual about my setup. Cygwin and
Linux should run the same shell scripts the same way (the simplest
example being the Hello world example).
Hmm, let's see, I have:
So I think I understand the problem (SHELLOPTS are set differently
under Linux and Cygwin) but I don't know how to control the definition
of SHELLOPTS to make them the same.
I can't change it in a bash script because it's readonly.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html