Question

I am running a customized script which includes a command (ios-sim) which should be known to bash (the binary lies in /usr/local/bin, $PATH knows). However, when invoked by xcodebuild the console logs "command not found".

I am able to execute the command manually, but I have no idea why it doesn't work within the run script. I have checked the user but as I expected it is both times the same user...

The line invoking ios-sim:

ios-sim launch $(dirname $TEST_HOST) $environment_args --args -SenTest All $test_bundle_path -v
Was it helpful?

Solution

Rather than relying on $PATH, the value of which isn't obvious, use the whole path to ios-sim.

Edit your custom script and change:

ios-sim launch ...

to

/usr/local/bin/ios-sim launch ...

The reason why using $PATH can be dangerous (perhaps too strong a word) is that it's not obvious where it's set. For example Xcode will use the path that's configured in /etc/launchd.conf and /usr/local/bin might have been added in /etc/profile or ~/.bash_profile.

  • Will launchd use the value in /etc/profile and thereby pass it to Xcode to use?
  • Will scripts started by Xcode use /etc/profile or ~/.bash_profile?

It's complicated and thorough understanding of this environment will doubtless allow you to invoke your command via $PATH, however using the fullpath to a command is a simple approach which will always work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top