Version and Build Information Error Xcode 4

1.1k views Asked by At

I'm using Xcode 4.3 and I have followed this user's steps to create the script:

Version vs build in XCode

For whatever reason it does not look like I can leave a comment there. As the answer area in StackOverlow is not a forum/discussion I'm a bit forced to ask a question based off that answer.

In Step 7 he cites 2 ways to increment Build Version: Number and Hex Number

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

and

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

Both are returning the exact same shell error:

syntax error: invalid arithmetic operator (error token is ".0")
command /bin/sh failed with exit code 1

I went the summary tab and both version and build were 1.0. If I change this to just "1" the error is "line 4 1 + 1: syntax error: invalid arithmetic operator (error token is " + 1")

What am I doing wrong and what can I do to fix this?

1

There are 1 answers

0
tilo On BEST ANSWER

Your build number has a floating point value, so change your code to

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

as suggested in this SO post.