delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/12/30/22:25:54

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE
X-Spam-Check-By: sourceware.org
Date: Fri, 30 Dec 2011 22:25:36 -0500
From: "cygwin at sipxx.com" <cygwin AT sipxx DOT com>
Subject: Re: SHELLOPTS=igncr and bash --posix
In-reply-to: <4EFE163B.9040908@gmail.com>
To: cygwin AT cygwin DOT com
Reply-to: cygwin AT sipxx DOT com
Message-id: <4EFE80B0.9080402@sipxx.com>
MIME-version: 1.0
References: <4EFCDE35 DOT 4040302 AT cpan DOT org> <4EFD54D1 DOT 9080508 AT gmail DOT com> <4EFDB169 DOT 6050107 AT cpan DOT org> <4EFE163B DOT 9040908 AT gmail DOT com>
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

SHELLOPTS is a read-only variable, you are not supposed to set it in bash.
No reason to look for bugs when you are using it incorrectly.

Dave Korn wrote:
> On 30/12/2011 12:41, Rafael Kitover wrote:
>   
>> On 12/30/2011 1:06 AM, Dave Korn wrote:
>>     
>>> On 29/12/2011 21:40, Rafael Kitover wrote:
>>>       
>>>> Some of my bash scripts, particularly ones that are #!/bin/bash --posix
>>>> trigger a nasty warning when I have SHELLOPTS=igncr set in my ~/.zshrc:
>>>>
>>>> rkitover AT eeebox ~/src/scala % echo $SHELLOPTS
>>>> igncr
>>>> rkitover AT eeebox ~/src/scala % bash --posix
>>>> bash: SHELLOPTS: readonly variable
>>>>
>>>> this is rather unsightly so I have turned off SHELLOPTS for now.
>>>>
>>>> Is this a bug? 
>>>>         
>>>   Bug in your script I'm afraid.  SHELLOPTS is indeed a readonly variable, it
>>> can only be set outside bash before starting it, definitely not from within a
>>> startup script.  (Perhaps the reason it seems associated with --posix is
>>> because that selects different startup files?  I'm guessing that you may have
>>> ENV=~/.zshrc because it's not normal behaviour for bash to read zsh's startup
>>> file!)
>>>       
>> I don't have ENV set.
>>
>> If I comment out the SHELLOPTS setting in ~/.zshrc then do this the
>> problem still appears:
>>
>> rkitover AT eeebox ~ % export SHELLOPTS=igncr
>> rkitover AT eeebox ~ % bash --posix
>> bash: SHELLOPTS: readonly variable
>> %{
>> %}(%n@%m)[%h] %{%}%~%{%}
>> $
>>
>> I do not have a ~/.profile, and ~/.bash_profile just reads ~/.bashrc. I
>> do not set SHELLOPTS in ~/.bashrc, it only has set -o igncr.
>>     
>
>   Ah, I'm guilty of trusting the documentation too much.  Turns out the
> problem is easy to reproduce without zsh being anything to do with it: even if
> you have SHELLOPTS set in the Windows environment and launch bash directly
> from cmd.exe, it still fails -
>
>   
>> Microsoft Windows 2000 [Version 5.00.2195]
>> (C) Copyright 1985-2000 Microsoft Corp.
>>
>> C:\Documents and Settings\Administrator>set | grep SHELLOPT
>> SHELLOPTS=igncr
>>
>> C:\Documents and Settings\Administrator>bash --posix
>> bash: SHELLOPTS: readonly variable
>> bash-4.1$
>>     
>
>   A bit of googling and I discovered this is apparently a known bug in
> upstream bash, reported on the GNU bug-bash list back in October at
> http://lists.gnu.org/archive/html/bug-bash/2011-10/msg00039.html.  A fix is
> promised for the next release but until then I'm afraid you're stuck with only
> being able to use one of SHELLOPTS and --posix at a time.
>
>   
>>>> If so, is a fix possible?
>>>>         
>>> Use "set -o igncr" instead.
>>>       
>> But if I want to use CRLF #/bin/sh scripts from zsh, then I have to set
>> SHELLOPTS.
>>     
>
>   You might be able to make it work by setting ENV (would be BASH_ENV, but
> you're using --posix) to point to a (LF-endings-only) script that contains
> "set -o igncr".  Hopefully that will take effect before the newly-launched
> bash has a chance to get upset by any CRs in the script file it's been invoked
> on.  (I can't guarantee that nothing will go wrong while parsing the shebang
> line if that ends with a CRLF, but you may as well give it a try.)
>
>     cheers,
>       DaveK
>
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>
>
>   

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019