bug-bash
[Top][All Lists]
Advanced

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

Re: the '-n' conditional


From: Doug Kern's
Subject: Re: the '-n' conditional
Date: Mon, 4 Jun 2001 22:30:58 +1000
User-agent: Mutt/1.2.5i

On Sun, Jun 03, 2001 at 04:18:56AM +0200, Per Fransson wrote:
> If this is the wrong group for this question can you please tell me who
> to ask?
> 
> Isn't
> 
> [-n string]
> 
> and
> 
> [string]
> 
> supposed to evaluate to exactly the same thing?
> 
> 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.
> 

You need to quote the positional parameter. If $1 == "", then unless you
quote it, it expands to nothing, and you are testing [ -n ] which always
evaluates to true.

Regards,
Doug



reply via email to

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