1

I'm a script kiddie of sorts and enjoy writing bash scripts for things, and I keep them in a repository that I synchronize, and on my personal computers I keep it in a home/otherStuff/customBin folder, but...

while I can add it to the .bashrc of every profile that gets tedious, and etc/environment doesn't seem to work for one reason or another.

(Edit) @steeldriver answered the below portion, but I still need the above question answered.

And the crux of the problem was, when I did "sudo customScript" it behaves like the file isn't on path, but doing "sudo -i" and then "customScript" does work just fine. How do I fix it?

"Under the default Ubuntu configuration, sudo uses its own secure_path in place of the environment's PATH - see for example Executable runs without sudo but not with sudo" – steeldriver

Jrome
  • 13

2 Answers2

1

The usual place to put user installed applications (and scripts) is /usr/local/bin.

You only need sudo to copy/sync the scripts to this location.

/usr/local/bin should be in your path, and if executable, scripts can be run by all users.

Artur Meinild
  • 26,018
  • This is good advice, but because I want to sync just my scripts with bin and don't want to worry about lingering old scripts if I delete one, or trying to .gitignore everything other than my stuff in that folder, because too many other programs already use that folder. – Jrome Sep 04 '23 at 22:19
  • @Terrance sure - fixed typo. – Artur Meinild Sep 05 '23 at 06:25
1

You should be able to make it a universal path by adding to the /etc/profile file and also make it add a check.

If you add the following to the bottom of the /etc/profile then when you reboot it should be able to add it to the path universally or globally:

# Check for script directory and add to path
if [ -e /home/otherStuff/customBin ]; then
    PATH=/home/otherStuff/customBin:$PATH
fi
Terrance
  • 41,612
  • 7
  • 124
  • 183