X-Spam-Check-By: sourceware.org Date: Tue, 16 Jan 2007 15:34:07 +1100 (EST) From: Luke Kendall Subject: Re: Changed handling of "!" in /bin/sh? To: cygwin In-Reply-To: <45AC4851.3090508@byu.net> MIME-Version: 1.0 Content-Type: TEXT/plain; CHARSET=US-ASCII Message-Id: <20070116043407.7CB7F83D05@pessard.research.canon.com.au> X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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 script files. > 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): Hello world\! 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: Linux script: braceexpand:hashall:interactive-comments:posix Linux interactive: braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor:posix Cygwin script: braceexpand:emacs:hashall:histexpand:history:igncr:interactive-comments:monitor:posix Cygwin interactive braceexpand:emacs:hashall:histexpand:history:igncr:interactive-comments:monitor:posixbraceexpand:emacs:hashall:histexpand:history:igncr:interactive-comments:monitor 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. Any advice? 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/