Adding Executable Program Commands to the PATH variable
Understanding the PATH variable and adding commands to use in your terminal
https://medium.com/codex/adding-executable-program-commands-to-the-path-variable-5e45f1bdf6ce
SHORT AND SWEET
create new bin folder to use to synlink application binaries to:
mkdir ~/bin
add new bin folder to PATH (add to ~/.zshrc config)
export PATH="/Users/spiffy/bin:$PATH"
then synlink the binary for an app (MACos it should be at:
App.app - "open package contents"/Contents/MacOS/(APPNAMEFILE)
synlink that file into the bin folder
ln -s "/Applications/flameshot.app/Contents/MacOS/flameshot" ~/bin
Terminal Commands
If you encounter the below error while running the command flameshot:
flameshot: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
Debian | apt-get install flameshot |
Ubuntu | apt-get install flameshot |
Arch Linux | pacman -S flameshot |
Kali Linux | apt-get install flameshot |
Fedora | dnf install flameshot |
flameshot Command Examples
- Create a fullscreen screenshot:
flameshot full
- Create a screenshot interactively:
flameshot gui
- Create a screenshot and save it to a specific path:
flameshot gui –path path/to/directory
- Create a screenshot interactively in a simplified mode:
flameshot launcher
- Create a screenshot from a specific monitor:
flameshot screen –number 2
- Create a screenshot and print it to the standard output:
flameshot gui –raw
- Create a screenshot and copy it to the clipboard:
flameshot gui –clipboard
- Create a screenshot with a specific delay in milliseconds:
flameshot full –delay 5000
PATH variable
Your computer (Mac or Linux, or a Unix-based system) has an environment variable called `PATH`, which contains a set of executable program directories that contain the executable programs.Executable programs are basically the commands you can use in the shell.
These include the essential boot-stage or early-stage required binaries as well as other general system-wide commands.
As per the Filesystem Hierarchy Standard (FHS), these commands are located hierarchically in the system as follows:

In addition to the system-level binaries, executable programs can also include host specific program commands.
When you install a program or application on your Mac through the
internet, the application will be available to execute using GUI,
usually from the /Application
directory.
In order to use the command line command to run the application,
however, the executable file for the application must be saved to
the PATH
variable. In other words, you must add the
directory of the executable program file for the application to
the PATH
variable in order to use the name of the
executable file as the command to run it from the shell.
When you install an application through a package manager, such
as Homebrew, it is symlinked to /usr/local/bin
,
which is usually included in PATH
.
For other direct program installations, it is your job to either save
the original executable file to the PATH
variable directly,
or symlink the executable file to a separate bin
folder,
which would be included in PATH
.
Let’s take a look at how we can go about adding these
local application commands to
the **_PATH_**
variable so that
we can use their commands in our shell.
Adding to PATH
In your zsh
shell profile (.zshrc
), you can
add the following:
export PATH=“/path/to/app/executable/file/directory:$PATH”
or
path+=“/path/to/app/executable/file/directory”
export PATH=
export PATH=“/path/to/app/executable/file/directory:$PATH
This syntax prepends
/path/to/app/executable/file/directory
to the existingPATH
variable.
export
command allows all child processes to inherit the marked variable.$PATH
refers to thePATH
variable value- assigning the
path
/path/to/app/executable/file/directory
to thePATH
variable with the trailing:$PATH
essentially adds the path to the front of the existingPATH
value with the separator:
- You can also append the path to the existing
PATH
(add to the end) by instead using
export PATH="$PATH:/path/to/app/executable/file/directory"
path+=
path+=“/path/to/app/executable/file/directory”
path
is another variable that is tied to thePATH
variable, but it is an array.PATH
andpath
are tied together, so changing either one will change the other.
- however the variables’ value syntax are different:
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/path/to/app/……>> echo $path
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /path/to/app/……
- Note the
PATH
is separated by:
whilepath
is separated by whitespace. - You can force the
path
variable to have only unique values by usingtypeset -U path
command beforepath
assignment. This will keep thepath
value clean by preventing duplicate directory names being added.
Here, the
path/path/to/app/executable/file/directory
will likely be a
application bin
directory starting from
the /Applications
directory.
- For example, for Visual Studio Code, the path is:
/Applications/Visual Studio Code.app/Contents/Resources/app/bin
- So, you would set:
export PATH=“/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH”
This allows you to use the ‘code’ command (which is the name of the executable file) to run Visual Studio Code from the command line.
Symlinking
the executable program file to a
personal bin
directory
Instead of adding each executable program file to
the PATH
separately, you can symlink the executable program
file to a separate folder and add this folder to
the PATH
.
- This separate folder could be a
bin
folder on your home directory:~/bin
. - You will have to create this in your home directory:
>> mkdir ~/bin
You can use ln
command to symlink the executable
file.
ln
is a utility program that creates a new directory entry (a linked file), which has the same modes as the original file. The link ‘points’ to the original copy. How the link ‘points’ to the original file is the difference between a hard link and a symbolic link.- By default
ln
creates hard links, where any changes to the original file are effectively independent from the linked file. - Using the
-s
flag creates a symbolic link (symlink), which is a soft copy, allowing for the use of the referenced file when an operation is performed on the linked file.
>> ln -s “/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code” ~/bin
If you have the ~/bin
directory added to
the PATH
variable, you just need to to symlink any
executable program you want to add command for to
the ~/bin
directory.
This will make the organization of the
PATH
much cleaner and much easier to see what executable programs are included in thePATH
.