4

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". I get an error saying:

Command /bin/sh failed with exit code 1 /Users/ricardodelfingarcia/Library/Developer/Xcode/DerivedData/Flat_Wars-bhkfhubvxegpazcnqcswodoejxeo/Build/Intermediates/Flat Wars.build/Debug-iphoneos/Flat Wars.build/Script-B6B328B815AA6F9900C26C37.sh: line 4: File Doesn't Exist, Will Create: Flat Invalid Arguments + 1.0: syntax error: invalid arithmetic operator (error token is "'t Exist, Will Create: Flat Invalid Arguments + 1.0") Parse Error: Unclosed Quotes Value Required for Set Command

What is the problem?

Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
rdelfin
  • 819
  • 2
  • 13
  • 31

3 Answers3

4

Problem is you have space in your directory name.

This will work:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
Matej
  • 9,548
  • 8
  • 49
  • 66
  • buildPlist=${INFOPLIST_FILE} newVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist" | /usr/bin/perl -pe 's/(\d+\.\d+\.\d+\.)(\d+)/$1.($2+1)/eg'` echo "Plist " $buildPlist " Version set to " $newVersion; /usr/libexec/PListBuddy -c "Set :CFBundleVersion $newVersion" "$buildPlist" – Darshan Kunjadiya Feb 09 '15 at 10:34
  • @matejkarmny is in my script what is the problem ? – Darshan Kunjadiya Feb 09 '15 at 10:37
  • Hi @DarshanKunjadiya, can you submit a new question? – Matej Feb 09 '15 at 11:22
0

The syntax error: invalid arithmetic... tells you that it's the second line where the error is. So just run the second line alone and echo $buildNumber, then you'll see why the PlistBuddy command didn't work and why it gave you the error "...doesn't Exist, Will Create: Flat ..."

rwst
  • 2,515
  • 2
  • 30
  • 36
  • I am new to shell scripts. I wanted to know where it prints. In the computer's console or on xcode's log? – rdelfin Jul 09 '12 at 23:49
  • @rickyman20 when you run it will run your script. any errors will be in the build log – Matej Apr 08 '13 at 13:35
0

Check if CFBundleVersion is present in your Info.plist.

Your script can't create CFBundleVersion if not present, and it stops working. Just add CFBundleVersion in your Info.plist and your script will update it.

Giuseppe Garassino
  • 2,272
  • 1
  • 27
  • 47