I'm using bash, and I want to be able to execute a script just by typing its name as a command, same as
pwd for example.
Is there a specific directory where I need to save my script to, or any other system files I need to edit to achieve this?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You have to install that script in one of the directories of
$PATH. Use (
echo $PATH) to see the directories of
That means either copy the script to
Or make a symbolic link to the script inside one of the directories of
Or append the script directory to
export PATH=$PATH:<script directory>
You can check what locations are currently checked for direct commands by looking at the
It's likely this includes
/usr/local/bin, in which case you could put a symbolic link there:
ln -s /opt/mysuperscript /usr/local/bin/mysuperscript
Now you can just type
mysuperscript to run your script.
You may want to check the
ln command. It can be used to create a link to a file or directory.
Try this link to get more infomation: ln command example