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

6
  • 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 Commented Sep 4, 2023 at 22:24
  • @steeldriver, That answers the crux of the problem I'm having, but not quite the full question I posed it in. I'll edit the question to include such.
    – Jrome
    Commented Sep 4, 2023 at 22:40
  • If you run sudo -l you will likely see that secure_path contains both /usr/local/sbin and /usr/local/bin Commented Sep 4, 2023 at 22:49
  • Still answering the crux of the problem driving the question, but still not the question. How do I add something to the systemwide path? Is there any way other than /etc/environment?
    – Jrome
    Commented Sep 5, 2023 at 0:39
  • Does this answer your question? Executable runs without sudo but not with sudo Commented Sep 5, 2023 at 6:29

2 Answers 2

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
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.

2
  • 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
    Commented Sep 4, 2023 at 22:19
  • @Terrance sure - fixed typo. Commented Sep 5, 2023 at 6:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .