Where Should I Put My Bash Scripts?

Where Should I Put My Bash Scripts?

I have a few very simple Bash scripts that I cobbled together for things that I do regularly.

One of them is to run duplicity to do my backup tasks. Nothing clever, just a bunch of if .. then statements really.

As this needs to be run as root, would it be best practice to put my script in /usr/bin (or another location on PATH), chown to root:root and chmod to 700?

10

3 Answers

If no other user other than you uses these scripts

Then you can keep them in /home/$USER/bin. Create the bin directory if it doesn't exist and move the files there. The bin directory in your home will automatically get added to the PATH environment variable. The code is in the .profile:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

See How to add /home/username/bin to $PATH?

Or in some systems it may be in .bashrc:

export PATH=${HOME}/bin/:${HOME}/.local/bin:${PATH}

Thanks Elder Geek.

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.