bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: the '-n' conditional


From: Chet Ramey
Subject: Re: the '-n' conditional
Date: Tue, 5 Jun 2001 10:39:51 -0400

> Isn't
> 
> [-n string]
> 
> and
> 
> [string]
> 
> supposed to evaluate to exactly the same thing?

If `string' is not null.

> When I run the following script:
> 
> #!/bin/sh
> if [ -n $1 ]
> then
>     echo Foo
> fi
> # end of script
> 
> it echoes "Foo" regardless of whether there's a first parameter or not.

If $1 evaluates to nothing, you're left with [ -n ], which is true.  Look
at the Bash FAQ, question E1.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]