The reason you couldn't launch your executable is because the shell look for the command in any of the paths defined in the PATH
environment variable (known paths from now).
You can check those known paths with:
echo $PATH
As you can see, /usr/bin
is defined there as well as other paths.
Anyway, you can get what you want in several ways.
Note below that when I use the ~ directory, the command will be only available for the current user.
Creating an alias my-editor
This is my favourite when you want to run a command which is not found in the known paths. It would be a good idea for you too. In bash
you can place the alias in ~/.bash_aliases
.
echo alias my-editor=/usr/share/my-editor/my-editor-executable >> ~/.bash_aliases
Creating a link to your file in some of the known paths
It's the way you have done it and just to clarify, if you had created the link in any of the known paths, it would have worked too.
ln -s /usr/share/my-editor/my-editor-executable /usr/bin/my-editor
Defining a function with name my-editor
I think it's too much due to your needs but it's up to you if want to give it a try. It can be useful for other purposes.
You must define it in a file read by your shell. e.g. ~/.bashrc
in bash
. Shell files invocation.
cat >> ~/.bashrc << "EOF"
function my-editor() {
/usr/share/my-editor/my-editor-executable "$@"
}
EOF
Adding /usr/share/my-editor/
to the PATH
You can add a new path to the PATH
variable. In Ubuntu, the PATH
variable is generally set in /etc/environment
and if you modify this file, the new path will be accesible for all users.
However, if you want to be the only one who has access to the new path, you can set it in one of the personal shell files. e.g. in bash
: ~/.bashrc
. Shell files invocation.
echo 'export PATH="$PATH:/usr/share/my-editor/"' >> ~/.bashrc
[bash
] Entering a command into the hash table
A singular way to get the same result in bash
is adding my-editor
into the shell hash
table. Again, you must add the command in some file read by bash
(~/.bashrc
).
echo 'hash -p /usr/share/my-editor/my-editor-executable my-editor' >> ~/.bashrc
Moving the executable to a known path
Finally, if you don't need the file (my-editor-executable
) in his current directory anymore, you can simply move it to a known path.
mv /usr/share/my-editor/my-editor-executable /usr/bin/my-editor