Search code examples
xcodebashversioncfbundleidentifierbuild-numbers

How to increase float build number by using script


Hello guys i have tried following ways but none of them helped me to increase it without having any error on command line.

My current build number is 1.4.0 , i wanna get 1.5.0..

get bundle version and build version values from info.plist file

BUNDLE_VERSION=$(/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" <my plist path>)
BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" <my plist path>)

increase build number by one

#BUILD_NUMBER=`echo $BUILD_NUMBER +1|bc` //have tried this one first but didnt work
BUILD_NUMBER=$((BUILD_NUMBER+=1)) //that one also didnt help

Any idea?


Solution

  • BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" <my plist path>)
    echo $BUILD_NUMBER
    

    increase build number by one

    NEWSUBVERSION=`echo $BUILD_NUMBER | awk -F "." '{print $3}'`
    NEWSUBVERSION=$(($NEWSUBVERSION + 1))
    NEWVERSIONSTRING=`echo $BUILD_NUMBER | awk -F "." '{print $1 "." $2 ".'$NEWSUBVERSION'" }'`
    echo $NEWVERSIONSTRING
    

    update build number in info plist in the main project

    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${NEWVERSIONSTRING}" <my plist path>