Quote:
Originally Posted by Star_Gazer
I did not know that there was a builtin version and one that is external (not sure if that is the right word).
...
Weird that there is two different 'test' commands, but at least now I know. I'll check out the "[" one as well (as I noted the file on disk in the same directories as 'test').
|
Yes -- "builtin" and "external" are the terms used in the shell documentation.
The concept of a shell is of a command interpreter and originally the shell itself was relatively lightweight with few builtins except for the ones that had to be such as
cd. Some external commands such as
test were used so heavily in shell scripting that the resource cost of having them as externals (create new process by
fork, load new program by
exec) reduced performance. The solution was to implement them as builtins.
echo is another good example.
The original externals were left in place for backward compatibility and for use from other languages, for example C can call
/bin/test and others via the
system call (even if there are better ways of implementing the same functionality in C!).
For current bash programming the
Conditional Construct [[ ]] is preferred to builtins test and [ (and definitely to externals test and [

) for reasons explained
here.