6

I observed the custom shell scripts executed by Xcode, in Run Script Phase, do not have any environmental variable set. They have tons of other variables but not the PATH.

Is it possible to solve this problem, how? I just want to run a tool that is supposed to be in path and I do not want to start checking manually possible locations.

sorin
  • 161,544
  • 178
  • 535
  • 806

3 Answers3

9

You could explicitly source the users .bashrc, .profile etc. Or better yet, run something like

PATH=$(bash -l -c 'echo $PATH')

which won't risk polluting other variables.

Ivan Andrus
  • 5,221
  • 24
  • 31
4

Ivan Andrus' answer led me to what I think is a cleaner and more complete method: run the script within a new shell altogether. For example:

bash -l -c "./configure --prefix=${DERIVED_FILE_DIR} && make && make install"

I'm using double-quotes for variable expansion. It's a good idea to expand out any variables you need, because any existing vars might be overwritten by the ones created for the new environment.

jgrandy
  • 71
  • 5
  • 1
    If you need an entirely fresh environment, there's a discussion of the options [here](http://superuser.com/questions/319043/runing-a-command-without-inheriting-parents-environment). – jgrandy Aug 22 '12 at 14:29
1

You might want to follow this thread: Setting environment variables in OS X? I have good luck with environment.plist.

Community
  • 1
  • 1
Hai Vu
  • 37,849
  • 11
  • 66
  • 93
  • You are right, considering that Xcode is an GUI application it may use the environment.plist, still modifying it is not acceptable because I want to include this in a build script, a script that should not require environment modification. – sorin May 26 '11 at 17:34