在OSX写入文件 - write to file in OSX

- 此内容更新于:2015-12-13
主题:

我有一个脚本。我让它自动构建iOS代码上载iTunesConnectMacMini。我的问题是,我必须改变CFBundleShortVersionString,隐藏我们的内部版本控制。同样重要的是,因为iTunesConnect警告我这版本是无效的!我的问题是,我回到下一个错误:任何想法?编辑:xcrunagvtool命令不解决这个问题,这是原因为什么我自己写脚本每个命令在句法上是正确的,当我运行它们明显,代码做我想做的事情。

原文:

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.

网友:你可能想要使用停止脚本的第一个错误。您可能还希望使用用于调试目的。错误显示的文件你想(有时无益地)不存在,和你使用的语法是错误的。我建议,使常见的字符串,如文件名、变量和使用shellcheck.net。

(原文: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) 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 shellcheck.net .)

解决方案:
使用(从)写版本字符串而不是:如果你想自动递增构建数字(一个好主意),那么看到这样的答案。
原文:

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.