Why is the output of $PATH different when in a script vs when running $PATH from the terminal? Even for a minimal script like this:

echo $PATH

it will not match what I get when typing in $PATH in the terminal. Because of this, I keep getting "command not found". How can I fix this? I'm using OSX High Sierra.

Ok, "export PATH" seems to have solved part of my problem. One of the programs that I am using though is dynamically linked. For some reason, even with export path it says "dyld: Library not loaded". At least now the program is in the path when called from the script. What does "export PATH" do? And how can I include the library paths as well?

  • 1
    Where do you run the script from? – nohillside Apr 3 '18 at 17:58
  • 1
    the shell by just typing bash ./script, for example – lenzinho Apr 3 '18 at 18:03
  • 1
    What are the results from- /usr/bin/grep PATH "$HOME/.bashrc"? – fd0 Apr 3 '18 at 18:23
  • 1
    What happens if you just run ./script (may need a chmod +x script first)? – nohillside Apr 3 '18 at 18:26
  • 1
    Please show us the contents of your script. Also, you should not just type $PATH, but rather something more like echo "$PATH" or env | grep -i "PATH" - that shows you the contents of the variable PATH, as opposed to your shell trying to run (the contents) as a command, which could present problems. Also, let's see which shell you're using: env | grep -i shell. Sounds like your script isn't inheriting your environmental variables, which isn't all that unexpected IMO.. we just need to figure out why. – Harv Apr 3 '18 at 18:37

You must log in to answer this question.

Browse other questions tagged .