if export PATH=$PATH:[path/to/program] is just a temporary solution, why do it for repeatable usage?
Like you say, it is a temporary solution for use in only a single session.
if I add export function for the path to bashrc and update it, it doesn't work either. And I suspect that it is because we haven't determined the name of the actual file?
.bashrc
is run each time you open an active terminal. If correctly entered in a location of the script that is run, it should work. If you prefer the entry to work always, e.g. also from a script run from a program laucher, or from the Alt+F2 run dialog, add the statement to .profile
instead. That file is read when you log in.
No, your suspicion is wrong. One a (valid) directory is added to PATH
, the system will search that directory for a file name matching a command you entered at the terminal prompt.
so it takes me to the question, how the system determines between commands and programs?
A command is a string you type in the terminal to execute something. It can be a shell builtin, or it can be an executable file. An executable file is a file where the executable bit has been set. It can be a script (bash, python, ...) or binary code. It may be a matter of semantics, but any command corresponds to some programmed code, be it a shell builtin, e.g. cd
or an executable file to launch, e.g. gedit
.
You can specify a full pathname to an executable. Then the shell will immediately locate it and (try to) execute it.
If you just type a name, the shell will start searching for something with that name to execute:
It checks whether the name corresponds with an internal command, i.e. a "shell builtin". A shell builtin resides in memory as part of your command interpreter, typically bash
in interactive shells on Ubuntu. cd
, pwd
, echo
and set
are examples of shell builtins (in bash).
Then it goes looking into the hash table, a trick to speed up finding executables. When you just logged in, the hash table is empty.
Then it proceeds inspecting each folder in your PATH
, in the order folders are listed. So if the path is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/games
, /usr/local/sbin
is searched for the string. If it is not found there, the system continues searching in he next directory, /usr/local/bin
etc. ls
and chmod
are example of executables.
You can learn about your commands with the type
command. For example:
$ type man
man is hashed (/usr/bin/man)
$ type ls
ls is aliased to `ls --color=auto'
$ type chmod
chmod is /usr/bin/chmod
$ type pwd
pwd is a shell builtin
You can identify and locate external executables with the which
command:
$ which cd
$ which ls
/usr/bin/ls
source ~/.bashrc
after updating it, what doesecho $PATH
output, and, finally, where is this program located? You should add the directory where the program is located toPATH
, not the complete path to the script/binary. – frippe Aug 17 '22 at 15:28source ~/.bashrc
.echo $PATH
shows me pathes in the $PATH so the path I have just added is also there:/juan/diskD/Programy/OpenRefine/openrefine-3.6.0
. The program is located in the openrefine-3.6.0 directory. – Juandev Aug 17 '22 at 16:39/juan/diskD
permit program execution? – steeldriver Aug 17 '22 at 16:43ls
shows green color, so I expect its executable. Properties read shell script. I don't know what are mount options on a specific directory, but I can initiate the program from its mother directory viachmod a+x *program*
and then/.*program*
. – Juandev Aug 17 '22 at 16:52/path/to/program
should be/path/to/directory/where/program/is/located/
. – mook765 Aug 17 '22 at 17:47