Aliases are personal tools
- I think aliases are intended for personal use (and should reside in each user's
~/.bashrc
file).
Shellscripts (and other programs) are general tools
Detailed tips
This is my path in Lubuntu 18.04.x LTS.
$ echo $PATH
/home/sudodus/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/games
I have an own bin
directory, which is automatically found and put in the beginning of the path (with highest priority). But the rest of the path is standard.
I would suggest that you
check that there should be no conflict with the name
type unique-name # shows if it exists and what kind of program it is
which unique-name # shows where an installed program is stored
unique-name # if known but not installed, you get a hint about it
apt-cache policy *unique-name* # package name (may or may not be same as program name)
if no conflict, create a shellscript (this is a trivial example)
echo 'echo "Hello World"' > unique-name
make the shellscript executable
chmod +x unique-name
put the shellscript into /usr/local/sbin
if it needs root privileges or otherwise into /usr/local/bin
.
sudo cp -i unique-name /usr/local/bin
The option -i
prompts you if the name already exists in the target directory.
How all users can run your shellscript
When you make the shellscript executable and it is in a directory in everybody's PATH
, everybody can run it via its file name,
unique-name
There are several short strings that are not yet used as names for standard programs, and you can find such names by testing with
type short-string-to-be-tested
for example
$ type py
bash: type: py: not found
In my computer there is no executable program and no shell built-in with that name, so I can use py
as a file name (and I need no alias).
But if you try to run py
before renaming your shellscript to that name,
$ py
Command 'py' not found, but can be installed with:
sudo apt install pythonpy
you will find that there is such a program (but it is not yet installed), and it might be a good idea to select another name, for example
pych
which can be a short name derived from your original name PyCharm.
~/.bashrc
file). I'll try to find a method to make it work to globally change an alias (but I cannot see a way right now). I think using a shellscript and put it in a directory, that is in "everybody's path" is a good way to do it. So I think your answer really contains a good solution, and not 'just a workaround'. For this reason I will upvote it ;-) – sudodus Dec 16 '19 at 13:33