2

I have a script. I made it for automatically build iOS code uploadable for iTunes Connect on a Mac Mini. My problem is, that I have to change the CFBundleShortVersionString, to hide our internal versioning. it is also important, because iTunes Connect warns me that the version is not valid!

#!/bin/bash
cat info.plist | grep -A1 "CFBundleShortVersionString" | sed "s/\(<string>\).*\(<\/string>\)/\1%CFBUNDLESHORTVERSION%\2/g" > info.plist_in.bk
cat info.plist_in.bk
cat info.plist | grep -A1 "CFBundleShortVersionString" | grep -v CFBundleShortVersionString | egrep "[A-z0-9]+" > delete.txt
cat delete.txt
cat info.plist | grep -v "CFBundleShortVersionString" > infoi.plist_in
cat infoi.plist_in
touch info.plist_in
cat infoi.plist_in | grep -v $(cat delete.txt) > info.plist_in
cat info.plist_in.bk >> info.plist_in
sed -i .bk2 -e "s/<\/dict>//g" info.plist_in 
sed -i .bk3 -e "s/<\/plist>//g" info.plist_in
echo "</dict>" >> info.plist_in
echo "</plist>" >> info.plist_in
cat info.plist_in > info.plist

My problem is, that I get back the next error:

cat: infoi.plist_in: No such file or directory
cat: delete.txt: No such file or directory
usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
    [-e pattern] [-f file] [--binary-files=value] [--color=when]
    [--context[=num]] [--directories=action] [--label] [--line-buffered]
    [--null] [pattern] [file ...]
cat: info.plist_in.bk: No such file or directory
sed: info.plist_in: No such file or directory
cat: info.plist_in: No such file or directory

Any ideas?

Edit: The xcrun agvtool command don't resolved the problem, this is the cause why I write my own script Each command is syntactically correct, when I run them distinctly, the code do what I want.

kisstajmi
  • 255
  • 2
  • 12
  • You might want to use `set -e` to stop the script at the first error. You might also want to use `set -x` for debugging purposes. The errors suggest the files you're trying to (sometimes [uselessly](https://en.wikipedia.org/wiki/Cat_(Unix)#Useless_use_of_cat)) `cat` don't exist, and that your use of `grep` is syntactically wrong. I recommend `man grep`, making common strings, e.g. filenames, variables and using http://www.shellcheck.net . – Biffen Jan 26 '15 at 07:40

1 Answers1

2

Use PlistBuddy (manpage) to write the version string instead:

$ /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString YourVersion" file.plist  

If you want to auto-increment the build number in the plist (a good idea) then see this SO answer.

Community
  • 1
  • 1
Droppy
  • 9,691
  • 1
  • 20
  • 27