This is the mail archive of the
mailing list for the Cygwin project.
Re: Changed handling of "!" in /bin/sh?
- From: Eric Blake <ebb9 at byu dot net>
- To: cygwin at cygwin dot com, luke dot kendall at cisra dot canon dot com dot au
- Date: Tue, 16 Jan 2007 06:31:42 -0700
- Subject: Re: Changed handling of "!" in /bin/sh?
- References: <20070116043407.7CB7F83D05@pessard.research.canon.com.au>
-----BEGIN PGP SIGNED MESSAGE-----
According to Luke Kendall on 1/15/2007 9:34 PM:
> 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". :-)
Yes, bash always has a read-only variable named SHELLOPTS. The difference
is whether it is exported to the environment, or local to the shell.
> Any idea how to turn it off?
set +o history
> I grepped in /etc/* and /etc/profile.d/*
> for SHELLOPTS but didn't find it.
And you won't, because by default the cygwin base files don't currently
export SHELLOPTS, for the very reason that it tends to interfere with
> In the System Env Vars in Windows I
> define SHELLOPTS to be igncr (only).
There you go - that is the action that exported it into the environment,
instead of leaving it shell-local.
> If I echo %SHELLOPTS% in a
> cmd.exe window it's set to igncr only. What's defining the other
bash, as part of it's normal operation, makes SHELLOPTS track all shell
options, not just the ones requested at startup.
> It's a readonly env variable, isn't it? I.e. I don't think I
> can correct it from within a bash shell?
You can correct it in bash indirectly by setting shell options.
> 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
> script files.
Have you considered using text mounts for your script files instead? I
intentionally ordered my recommendations in the release announcement in
the order that I thought were most supported; and setting SHELLOPTS is a
lower-rated feature (in my mind) than using proper line endings or proper
> 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!
Then write wrappers around your development tools that disable igncr, or
write a script and set BASH_ENV pointing to that script that only sets
igncr if the current shell is interactive (if $- contains i), rather than
setting SHELLOPTS. Or use /bin/sh instead of /bin/bash as your shell.
> Are the extra options being turned on automatically only for
> interactive shells?
Yes - the fact that you ran bash interactively first is what set the
interactive shell options that are in conflict with POSIX, and the fact
that you exported SHELLOPTS is why /bin/sh picked up on those same options.
> Do you mean that if I want POSIX behaviour from
> shell scripts then I can't have history for interactive shells?
No, you just have to be more careful about how you go about getting igncr
> Perhaps a simple workaround is to replace /bin/sh with /bin/ash?
If you use /bin/sh as your login shell, then fewer options will be set in
SHELLOPTS automatically. I would not recommend using /bin/ash; the
version on cygwin is quite buggy, and lacking several POSIX-compliant
fixes that linux compilations have added in the past few years.
> I'm puzzled that others haven't found the same problem, so I still
> suspect there must be something unusual about my setup.
Actually, others have reported the problem of SHELLOPTS interfering with
scripts before. I just haven't had time to try and analyze how easy or
hard it would be to patch bash to unset interactive options when starting
Don't work too hard, make some time for fun as well!
Eric Blake firstname.lastname@example.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html