写入 OSX 中的文件

write to file in OSX

我有一个脚本。我制作它是为了在 Mac Mini 上为 iTunes Connect 自动构建可上传的 iOS 代码。我的问题是,我必须更改 CFBundleShortVersionString,以隐藏我们的内部版本控制。这也很重要,因为 iTunes Connect 警告我版本无效!

#!/bin/bash
cat info.plist | grep -A1 "CFBundleShortVersionString" | sed "s/\(<string>\).*\(<\/string>\)/%CFBUNDLESHORTVERSION%/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

我的问题是,我返回了下一个错误:

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

有什么想法吗?

编辑: xc运行 agvtool 命令没有解决问题,这就是我编写自己的脚本的原因 每个命令在语法上都是正确的,当我 运行 清楚地看到它们时,代码会执行我想要的操作。

使用PlistBuddy (manpage) 来写版本字符串:

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

如果您想在 plist 中自动增加内部版本号(一个好主意),请参阅 this SO answer