mkshortcut fails when run from setup, postinstall/cygwin-doc.sh - not otherwise

Eric Blake eblake@redhat.com
Wed Dec 20 16:37:00 GMT 2017


On 12/20/2017 06:59 AM, Enrique Perez-Terron wrote:

> So I have added a line "set -x" at the top in postinstall/cygwin-doc.sh, 
> and the relevant section becomes
> 
>   + read target name desc
>   + '[' -r ']'

> 
> 
> (by the way -- this reveals another bug too: The script says "[ -r $t ] 
> && $mks ..." where I am sure it should be "[ -r $target ] && $mks ...")

Or, rather,

[ -r "$target" ]

It is almost always a bug to use [ ] without quoting "$..." expansions, 
because if the expansion of $... is empty, it changes the number of 
arguments to [ and thus the test that [ performs.

If your script uses #!/bin/bash, then you can use bashisms like:

[[ -r $target ]]

which do the right thing ('[[' is part of the shell grammar, rather than 
treated like an executable; as such, you can safely omit quoting in that 
form; but '[[' is not yet POSIX and is not supported on dash).

> (and again btw, I am not sure bash should count "[ -r ]" as a true 
> statement)

I am.  POSIX requires that behavior.  Any time you have exactly one 
argument to '[', the result is true unless that argument was the empty 
string.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

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



More information about the Cygwin mailing list