xcode - 使用运行脚本比较来自 info.plist 的值

标签 xcode shell

我的 info.plist 文件中有两个值,比如 string1 和 string 2

我想添加一个运行脚本来比较两个值并在值不相等时调用构建错误。

我是脚本新手,我遇到了一些语法问题,这是我到目前为止所取得的成就

set string1 to $(/usr/libexec/PlistBuddy -c "Print string1" "${PROJECT_DIR}/${INFOPLIST_FILE}")
set string2 to $(/usr/libexec/PlistBuddy -c "Print string2" "${PROJECT_DIR}/${INFOPLIST_FILE}")

echo string1
echo string2

if string1 = string2 then
echo "no errors" else
echo "generate build error in xcode"

非常感谢任何指点。 谢谢

最佳答案

您遇到的错误是因为 if else 循环中的错误语法和变量的设置值

# Basic value settings to the variable from the command execution
string1=$(/usr/libexec/PlistBuddy -c "Print string1" "${PROJECT_DIR}/${INFOPLIST_FILE}")
string2=$(/usr/libexec/PlistBuddy -c "Print string2" "${PROJECT_DIR}/${INFOPLIST_FILE}")

#Below is the basic if else loop in shell scripting with string comparison
if [ "$string1" = "$string2" ]
then
    echo "EQUAL"
else
    echo "NOT EQUAL"
fi

希望这对您有所帮助。

关于xcode - 使用运行脚本比较来自 info.plist 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21823702/

相关文章:

linux - 使用单个 Linux 管道查找和更改密码

c - 如何获取C语言执行shell命令的响应结果?

C++在shell中执行许多命令

objective-c - 是否可以让上层识别一种手势,同时将其他种类传递给下层?

ios - 无法在设备上启动应用程序

iphone - 如何在 Xcode for iPhone 中制作多页面应用程序?

java - Unix: "ls"命令显示带 ? 的文件延长后

iphone - 仅当通过 iPhone 中的 UIActivityViewController 发布成功时才想执行一些操作

ios - 由于该应用程序崩溃,字典获得零值。展开可选值时意外发现 nil

linux - 如何使用 shell 脚本使用来自标准输入(键盘)的信息更新文件?