On Tue, 5 Dec 2006, Uwe Dippel wrote: > 2 humble suggestions to make my server OS of choice even better. > > I seem to have found a bug in ksh: > Here is a sample that doesn't behave as I'd expect it to. > > # demo="" > # if [ "$demo" == "-n" -o "$demo" == "-e" ]; then > > echo bar > > fi > # demo="-n" > # if [ "$demo" == "-n" -o "$demo" == "-e" ]; then > > echo bar > > fi > ksh: [: -n: unexpected operator/operand > > IMHO, I'd consider it a bug, since the correctness of syntax must > not change with the value of the variable.
It's probably more of a feature. Probably the correct name for it is a "wart". The nature of name expansion in ksh, and the syntax of the [ and other things is such that demo="" should correctly expand to <nothing>, but the syntax of [ wants <something> before a ==. So in this sense, it is not a bug. It's a disappointment, maybe. The idiom used when a null value of "demo" matters is: # demo="" # if [ X"demo" == X"-n" -o X"demo" == X"-e" ]; then > echo bar > fi You'll see this throughout scripts in OpenBSD, see /etc/rc for examples > AFAIK, this syntax is considered correct generally; if not, please > advise me. If you mean "generally in the world of Bourne and Korn shells", then no, it's not correct. If you mean "generally when considering language design" then I agree. It all hinges around the nature of name expansion in ksh/sh, i.e. the way sh parses a command line, which is in various passes. The man page for ksh will provide insight. Dave > Secondly, I still need to resort to gtar for the backup of my users' home > directories (you know those silly long filenames in WORD). > I understand it is just a frontend to pax ? If it could process The system tar is a frontend to pax. I don't know about gtar.