Quote:> Hi,
> I am a little confused if the following shell testing clauses are the
> same, or, if not, what would be the benefit for using one over the other?
> Using /bin/sh,
> [[ -f /tmp/myfile ]] && echo "cool, file exists!"
> or
> [ -f /tmp/myfile ] && echo "cool, file exists!"
> I've always used the second form, but in HP-UX's /sbin/init.d/* init scripts,
> most lines use the first form, so, is there any good vs bad thing to use one
> of them instead of the other?
The [[ ... ]] construct will not work in a bourne shell script. The
bourne shell has no internal testing capability, and one has to rely
on the Unix test command which can be invoked as either:
test expression
[ expression ]
The Korn shell does have the ability, and of course it can also invoke
Unix programs just like any other shell. The [[ expression ]]
construct invokes the KSH builtin testing feature, which is obviously
much faster than executing an external program.
The default shell under HPUX is ksh, not sh, so in scripts where the
#! is ommitted from the first line, ksh is invoked to interpret it.
In short, the init files you looked at were Korn shell scripts.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Consulting wrong with a world in which Ken
Modeling Thompson lives in obscurity and
Training Bill Gates is a famous billionaire.
//////////////////////////////////////////////////////////////////////