There is another way (somehow not already mentioned) by using shell profile (.bashrc
, .zshrc
etc).
You can run:
# Assuming it is a script you made, changing file permission to make it executable
chmod a+x ~/directoryA/directoryB/directoryC/directoryD/somefile
# Appending your shell profile with an alias to run the script from wherever you are
echo "alias somename=\"source ~/directoryA/directoryB/directoryC/directoryD/somefile\"" >> ~/.profile
# replace ~/.profile with config file of whichever shell you use
# Also replace source with python if the script is a python script or whichever interpreter it requires for execution
# Make sure you have #!/usr/bin/env python or #!/path/to/interpreter on your computer as the first line of your script
Although above method allows the script to be run from anywhere you should make sure the script doesn't depend on the pwd
(present working directory) for execution (unless intended).
You can then run the script as executable in any directory, like:
somename
P.S.:
As for why not append the directory to PATH was simply under the assumption that only the single executable was to be added and not a directory full of executables like adb-platform-tools in which case appending the directory path to PATH would be the method to use.
directoryD
andDirectoryD
are not the same./home/directoryA
is probably meant to be/home/ME/directoryA
. Also thecd /directoryA/directoryB....
is missing the~
prefix. Also thecd
ends in.../somefile
which is impossible to change directory to a file. There are lots of flaws that need to be overlooked.