Running Executables

Executables are often also called binaries. The terms are synonymous in most cases.

The shell has a predefined search path. It will look in a sequence of directories for an executable with the specified name, and will invoke the first one it encounters. If the executable is in this search path, you can simply type its name at the prompt.

$gedit hello_world.sh

here gedit is the name of the executable. Its actual location is /usr/bin/gedit, but /usr/bin is in the default search path.

If the location of the binary is not in your search path, you must type the path to the executable (it can be absolute or relative)

$./hello_world.sh

For security reasons the current directory is not in your default search path. Hence you must explicitly provide the ./ path to execute a binary in the current directory. If you wish to add it, type (for bash)

$export PATH=$PATH:.

PATH is called an environment variable. It holds the list of paths to be searched by the shell. In this example it is essential to add the first $PATH or you will lose the default path set by the system.

If you are unsure of the path to the binary you wish to run, the which command will tell you the path to the binary the shell will start.

$which g++
/apps/software/standard/core/gcc/11.4.0/bin/g++
Previous
Next