rdelfin
rdelfin

Reputation: 816

Bash script in xcode returning Shell Script Invocation Error

I have this script made to autoincrement the build number on every build:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $INFOPLIST_FILE)
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" $INFOPLIST_FILE

I inserted it on the build phases before the "copy bundle resources". First, in the Shell Field I left the default /bin/sh but it gave me a Shell Script Invocation Error saying:

Command /bin/sh failed with exit code 1

So i looked up what to do and I discovered that changing the Shell to /bin/bash could fix it. I did so and I still have the same error. It still tells me that the Command /bin/sh failed with exit code 1. Why is it still telling me I have an error with /bin/sh if it does not exist anymore?

Upvotes: 2

Views: 1908

Answers (4)

arango_86
arango_86

Reputation: 4435

Same issue happened for me as well. Deleting the Derived Data and then clean and build is fixing the problem.

Upvotes: 0

karlbecker_com
karlbecker_com

Reputation: 959

I just ran into a similar problem after using the new Fabric Cocoapod with my Xcode project.

I had to change the Fabric script from: ${PODS_ROOT}/Fabric/Fabric.framework/run ... to: "${PODS_ROOT}/Fabric/Fabric.framework/run" ... because I have a space in the name of the one of the directories leading up to my cocoapods root location:

~/Documents/My Directory Name/My_Xcode_Project_Directory/

Upvotes: 0

jayemko
jayemko

Reputation: 216

I understand this question is over a year and a half old, but when searching this issue this question appeared at the top of search results. I found a different fix I wanted to share:

Here are the error details that I received when using the plistbuddy script (I assume this is the same error the OP saw as well).

Set: Entry, ":CFBundleBuildVersionString", Does Not Exist
File Doesn't Exist, Will Create: /Users/*YourFilePathHere/YourAppName*.app/Info.plist
Set: Entry, ":CFBundleBuildDateVersionString", Does Not Exist
Command /bin/sh failed with exit code 1

Screenshot Command bin sh failed with exit code 1 error

I tried to clean and deleted Derived Data without success. Turns out the actual solution was quite simple. I found that during build the script was trying to add the generated values to the plist before the plist was actually generated by Xcode.

Screenshot Target Build Phases

Targets > Build Phases > Extra Version Data is there this script is ran. However Targets > Build Phases > Copy Bundle Resources is where the plist is generated.

Screenshot Target Build Phases

Click and drag Extra Version Data so that it becomes listed after Copy Bundle Resources thus, the plist is built BEFORE the script tries to add the generated values.

Screenshot Target Build Phases Corrected

Then build and rejoice with a beer.

(Using Xcode 5.1)

Upvotes: 3

kjs
kjs

Reputation: 41

I just had this problem and found that I had a space in the filename for my INFOPLIST_FILE from a result of creating a new target and XCode appending the suffix ' copy'. It seems that PlistBuddy can't handle that space the way this script is created.

Once I renamed the file without the space and updated the name to match in the build settings this error went away.

Upvotes: 0

Related Questions