[TIP] Command line applications in $PATH

A tip for all developers on Raspberry Pi (Raspbian) developing command line (terminal) applications.

You want your command line application to respond to:

Replace “pi” in the paths with your username, the default is “pi”.

Where “myApplication” is your application name (ofcourse) and “-help” is the first command line argument (args(1)).
As you can see there is no path e.g. “/home/pi/myApplication” in the command. That’s because we will create a /home/pi/bin folder
where it will be automaticly added to $PATH. $PATH is the environment variable containing all paths where raspbian will look for your “myApplication” name.

So to start we need to add the “bin” folder to “/home/pi/”
connect using ssh in your raspberry pi or open the terminal application on your raspberry pi.

start with the following command:

(if this doesn’t work use “sudo” before “mkdir”)

now let’s see if the folder was created

You should see a dir named “bin”

Now open a ftp program. I use filezilla and select “SFTP” with “Logon Type” “Normal”.
Add your pi username example “pi” and the password.
Scroll to your “home/pi/bin” (Where “pi” is the username) directory, and upload your consoleapplication.

Reboot your pi, and your console application should be responding to any command using the “myApplication” name without the path infront of it.
To check use terminal on your pi or a console with ssh and type:

Replace “-help” with the first argument.
You should see the output of your console application.