Xcode Build Script (Build Phases-> Run Script) Increment Build Version based on username (username)

When compiling a project, this script should increase the build version of the Xcode project by one when the system name matches. Keep in mind that these are just Unix commands in a script (not Applescript, Python or Perl) inside Target-> Build Phases-> Run script in Xcode.

I made "echo $ USER" in the terminal. This prints the username of the registered user just fine, and this is the same line that I put in the conditional statement in the second block of code.

The first block of code works. The second, which the conditional operator adds, does not.

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


 #!/bin/bash username=$USER if [ username == "erik" ]; then buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE") buildNumber=$(($buildNumber + 1)) /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE" fi 

Syntax:
$ USER parsing (case sensitive)
The semicolon immediately after closing the brackets in the if statement
Then the operator on the same line as the operator

+7
source share
1 answer

You can see the script log in the Log Navigator, with your script I had the following problem:

enter image description here

I believe the default comparison is case sensitive, to make it case insensitive, you can change the username to upper or lower case before the comparison:

 if [ `echo $USER | tr [:lower:] [:upper:]` = "USERNAME" ]; then echo "Got user check" fi 

As you can see, I moved $ USER to this condition to avoid the extra use of var and script errors.

And the semicolon in the if-then block is a common thing, check the man page. The word then can be wrapped in a new line if you are more comfortable reading.

+4
source

All Articles