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?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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
non-interactive scripts.

>  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
> things?

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
mount points.

> 
> 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
behavior.

> 
> 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
non-interactively.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----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

iD8DBQFFrNO984KuGfSFAYARAhJmAJ4kq9rK5pmj+lMeM06vtGNFhcxztwCeNaWJ
Ax09lfzodr16Sqg78/NlAoM=
=Mdu0
-----END PGP SIGNATURE-----

--
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]