Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why PATH is not available for custom shell scripts executed from Xcode?

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.

like image 422
sorin Avatar asked May 26 '11 06:05

sorin


People also ask

Why my shell script is not working?

First of all make sure you have executable permission for your script. And then, Run your script using ./portblock.sh or using sh portblock.sh . If you don't like to run the script with above mentioned way then update your PATH variable to the script directory.

How do I run a script in Xcode?

1 Select xcodeproj file of you project -> Select Target -> Select Build Phases -> Click on plus button (upper left corner) -> Select New Run Script Phase. 2If you want to run a script while it is being installed on the device then please check a little checkbox just below the script box.


2 Answers

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.

like image 127
Ivan Andrus Avatar answered Nov 15 '22 07:11

Ivan Andrus


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.

like image 35
jgrandy Avatar answered Nov 15 '22 05:11

jgrandy