[colug-432] Shell Tests: Beware of leading '-'; Thanks Rob

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Tue Oct 6 18:34:09 EDT 2015


On Tue, 6 Oct 2015 18:21:53 -0400, Rob Stampfli <rob944 at cboh.org> wrote:

> On Tue, Oct 06, 2015 at 05:21:56PM -0400, jep200404 at columbus.rr.com wrote:

> >     [ "z${1}" = "z" ]
> >     [ "${1}" = "" ]
> > 
> > The last of those above is curious.
> > Since it works the same as with 'z', why bother with the 'z'?
> 
> It used to be that the "test" command got confused when the first
> argument started with a dash, so shell programmers routinely
> prepended an alpha to cover this case.

Thanks Rob. I should have thought of that. 

Any comments on the ${var:+value} stuff?
It is on page 4-7 (The Bourne Shell and Korn Shell chapter)
of the June 1998 printing of "UNIX In A Nutshell" that has
1986 and 1992 copyrights. 

I guess as long as the value does not start with a '-',
it should work fine also.


More information about the colug-432 mailing list