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