Running Any Executable
Problem
You need to run a command on a Linux or Unix system.
Solution
Use bash and type the name of the command at the prompt.
$someprogDiscussion
This seems rather simple, and in a way it is, but a lot goes on
behind the scenes that you never see. What’s important to understand
about bash is that its basic operation is to load
and execute programs. All the rest is just window dressing to get ready
to run programs. Sure there are shell variables and control statements
for looping and if/then/else
branching, and there are ways to control input and output, but they
are all icing on the cake of program execution.
So where does it get the program to run?
bash will use a shell variable called
$PATH to locate your executable. The $PATH variable is a list of directories. The
directories are separated by colons (:). bash will search in each
of those directories for a file with the name that you specified. The
order of the directories is important—bash looks at
the order in which the directories are listed in the variable, and takes
the first executable found.
$ echo $PATH /bin:/usr/bin:/usr/local/bin:. $
In the $PATH variable
shown above, four directories are included. The last
directory in that list is just a single dot (called the dot directory, or
just dot), which represents the current directory. The dot is the name of the directory found within every directory on a Linux or Unix file system—wherever you are, that’s the directory to which dot refers. For example, when ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access