In sh, is '[' a portable synonym for 'test'?
Guy Harris
guy at sun.uucp
Sat Oct 19 05:52:12 AEST 1985
> if test -f "$1" <= 15 keystrokes + <CR>
> vs.
> if [ -f "$1" ] <= 14 keystrokes + <CR>
>
> Which is more readable?
The latter, obviously; it reads more like a conditional statement rather
than a command. It may be *implemented* as a command (which, if the command
isn't builtin, slows it down - somebody who complained that "test" shouldn't
be built in was later seen using a "case" statement instead of an "if" and a
"test" in order to make it run faster), but that fact isn't relevant to
understanding what it *does*.
Good grief, do you think that people use the square bracket to save one
measly keystroke? That's not why it's there - it's there to improve the
readability of the statement.
Guy Harris
More information about the Comp.unix.wizards
mailing list