March 15, 2001, 3:39 PM —
Why is it that some commands can simply be executed, while others must be
./executed? In other words, why do some commands need a dot-slash in front of them to run? Rather than giving you a short answer, I am going to explore a couple of things and hope you find them enlightening.
If you create a new shell script, will you be able to run it with the first command below, or will you need to resort to the second?
$ newscript $ ./newscript $
Commands in Unix are either builtins or executables. Builtins are part of the shell you are currently running. Examples include
Any command that is not built in must be an executable. There are two types of executables: shell script languages, such as
perl, or compiled executables, such as a program written in C and compiled down to a binary.
Commands created by using an alias in
ksh also break down into these two main categories, because the command is translated and then issued as either a builtin or an executable. The following examples create aliases for the builtin
echo and the executable
The shell can always locate builtins, because they are built in to the currently executing shell.
$ alias sayit='echo ' $ alias g='grep '
In each case, after alias substitution is completed, the command becomes a builtin or an executable.
You can use the
type command to verify the nature of
$ type echo echo is a shell builtin $
Now use the
type command to check on