Change in behavior of bash / if [

Eric Blake eblake@redhat.com
Wed Dec 18 04:08:00 GMT 2013


On 12/17/2013 08:02 PM, Buchbinder, Barry (NIH/NIAID) [E] wrote:
> Today, a script that I use every day stated giving me the following
> error message.  (I grant that it might have started earlier and I
> didn't notice.)  Note that although it gave the error message, the
> script seems to still have worked.
> 
> ./lddir: line 77: [: too many arguments
> 
> Line 77 was as follows.  I'm testing whether $1 is "clip".
> 
> if [ x$1 = xclip ]

What was $1 at the time?

> 
> I fixed it with this.
> 
> if [ "x$1" = xclip ]

Yes, this is the correct fix for the improper quotation of the earlier
example.

> 
> 32-bit, everything was up to date.
> 
> I've solved my problem, but the change was unexpected and, for me,
> inexplicable, so I thought that I'd report it.

Your quoting error would produce the same message on Linux; it is not
cygwin-specific.

> 
> Let me know if you want/need more information.

Without knowing how $1 was set, I can only guess that it contained
something with characters in $IFS and therefore the word-splitting of
the unquoted use caused too many arguments to [.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20131218/f8b797c8/attachment.sig>


More information about the Cygwin mailing list