When compiling a project, this script should increment the Build Version of the Xcode project by one, when the system username 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've done "echo $USER" in terminal. This prints the username of the logged-in user just fine, and it's the same string I placed in the conditional statement in the second block of code.
The first block of code works. The second, which adds the conditional statement, 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 concerns:
Parsing of $USER (case sensitive)
Semicolon right after closing bracket in if statement
Then statement on same line as if statement
You can see the script log in the Log Navigator, with your script i've got the following issue:
I believe the default comparison is case sensitive, to make it not sensitive you can change the username to uppercase/lowercase before comparison:
if [ `echo $USER | tr [:lower:] [:upper:]` = "USERNAME" ]; then
echo "Got user check"
fi
As you can see I moved $USER to the condition to avoid additional var usage and the script failure.
And the semicolon at if-then
block is a normal thing, check the man page. then
word might be moved to the new line if that is more convenient for you to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With