I have added a directory to my PATH variable to access all my bash scripts. I add the PATH globally on the system under /etc/profile.d/custom.sh as follow:

export PATH=$PATH:/usr/local/bin/helper

This works, but when I call them in another script they are not found. Only if I use the full path to there location or I add a source /etc/profile.d/custom.sh at the top of an script they run.

All Scripts have a #!/usr/bin/env bash at the top.

Is there another way, or have I missed something?

  • In a terminal window does echo "$PATH" return the expected (new) result? – roaima May 14 '18 at 6:48
  • yes, i have checked this – HerrHase May 17 '18 at 14:57
  • 1
    Are you running your code from a cron job? – Kusalananda May 20 '18 at 17:29
  • Does ls /usr/local/bin show drwxr-xr-x ? - Same for /usr/local/bin/helper ? And the files inside helper are all r-x for other? -- I'm a little hazy about this, but I believe the "profile" files get read for a login shell, but not for non-interactive shells. Is it possible that your custom.sh just isn't being run in the environment in which you expect it to be run? – Joe May 23 '18 at 5:14

What might happen is that the default scripts are overwritten by your local custom scripts (you may have modified it locally or just simply forgot to execute default scripts).

Try to add a call to the custom.sh script in your user scripts (at the bottom of ~/.bashrc file):

# Running custom.sh
source /etc/profile.d/custom.sh
  • Hm, i have tried, but it makes no difference – HerrHase May 17 '18 at 14:58
  • 1
    Adding it to ~/.bashrc should have done it. For debugging, you might want to have custom.sh write a line of text with a timestamp to a file somewhere just so you can prove whether it was run at all. If you just call it from a .profile file, everything you source will be unavailable as soon as you go another shell level deeper. – Joe May 23 '18 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.