shopt igncr not working

Rob Walker rwalker@qualcomm.com
Fri Oct 13 22:10:00 GMT 2006


Matthew Woehlke wrote:
> http://cygwin.com/acronyms/#PPIOSPE, thanks!
>
> Rob Walker wrote:
>> Matthew Woehlke wrote:
>>> Rob Walker wrote:
>>>> Matthew Woehlke wrote:
>>>>> Rob Walker wrote:
>>>>>> Many, many other cross-platform products make allowances for CRLF 
>>>>>> (version control systems are a prime example) to maximize 
>>>>>> compatibility, and thereby their usefulness, on Windows.  
>>>>>> Cygwin's recent changes (with make and bash) here has put a real 
>>>>>> crimp in my plans to depend on cygwin for a portable build 
>>>>>> environment.
>>>>>
>>>>> I think using 'igncr' should satisfy your complaints. If it 
>>>>> doesn't, you need to tell use WHY (which, you'll notice, the OP 
>>>>> failed to do).
>>>>
>>>> So far, igncr hasn't worked for me either.  I think this is because 
>>>> I don't know how to use it.
>>>>
>>>> This is the simple shell script I'd like to have work (lines 
>>>> separated by CRLF):
>>>>
>>>>   #!/bin/bash
>>>>   echo helloworld
>>>>
>>>> [snip]
>>>> I also tried editing the script (which I fear breaks it for non 3.x 
>>>> users of bash):
>>>>
>>>>   #!/bin/bash -O igncr
>>>>   echo helloworld
>>>
>>> Did you try adding 'shopt igncr' to the script? This won't 
>>> (shouldn't, at least!) break it for non-3.1-9 users (and if you stick a
>>> 2>/dev/null after it, won't print errors).
>>
>> A ha!  This form works in 3.1-9
>>
>>    shopt -s igncr; #
>>    #!/bin/bash
>>    echo hello world
>
> Hmm, that should be the second line, not the first (not sure but I 
> would guess the shebang is ignored when it isn't first). Does it still 
> work that way, or does bash get confused about the CR on the shebang 
> line? (If the latter, I would say this is a real bug that needs to be 
> addressed somehow, or maybe igncr should affect the invoking bash's 
> handling of the shebang).
Yes, works if the second line too.  Thanks for your patience.  Here's a 
working version:

   #!/bin/bash
   shopt -s igncr 2>/dev/null; # please keep me on the second line, thanks
   echo hello world


>
>> But it apparently _does_ break for non-3.1-9 users:
>>
>>    rwalker@sycophant> ./helloworld.sh
>>    shopt: not found
>>    hello world
>>    rwalker@sycophant> bash --version
>>    GNU bash, version 2.05b.0(1)-release (i686-pc-cygwin)
>>    Copyright (C) 2002 Free Software Foundation, Inc.
>
> It does? It looks like it did what it is supposed to do; gripe, and 
> then correctly run the rest of the script. See my earlier suggestion 
> about adding '2>/dev/null' after the 'shopt'.
You're right, sorry about that.  The script succeeded in this case, too 
(returned 0).

-Rob


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



More information about the Cygwin mailing list