At 2025-11-18T14:19:50-0800, Collin Funk wrote:
> Isn't this way of comparing, e.g.
> 
>    if "x$var" = x; then

(You need "test" or "[" and "]" here.)

>      :
>    fi
> 
> to support ancient shells?

Yes, but. :(

Just quoting the variable _should_ be enough.  But I have read tales
that some shells _still_ manage to screw this up.[1]

Consider...

test "$var" = "whatever"

...when the value of var is "-n" or "-z", for instance.  If the shell
performs quote removal "too early", it's likely to pass incorrect
arguments to test(1).

Fortunately, every shell on my Debian box does NOT have this problem.

$ for shell in bash dash mksh ksh93 yash zsh; do printf "%s " $shell; $shell -c 
'export var=-n; if [ "$var" = "yes" ]; then echo OK; else echo also OK; fi'; 
done
bash also OK
dash also OK
mksh also OK
ksh93 also OK
yash also OK
zsh also OK

Perhaps it is impossible to avoid if "test"/"[" is not a shell builtin?
Do any shells of that description still live?

> I think we assume a reasonable shell for
> ./configure.

I sure hope so.  The old "x$var" idiom is hideously ugly and
off-puttingly confusing to newcomers.

Regards,
Branden

[1] 
https://stackoverflow.com/questions/174119/why-do-shell-script-comparisons-often-use-xvar-xyes

Attachment: signature.asc
Description: PGP signature

Reply via email to