gpt4 book ai didi

xcode - 处理 Xcode 构建阶段 Bash 运行脚本中的空格和特殊字符

转载 作者:行者123 更新时间:2023-12-05 04:13:53 28 4
gpt4 key购买 nike

我的 Xcode 项目的 Build Phases 中有一个自定义的 Bash Run Script。它将官方版本号写入 plist。

#proper escape for spaces
TARGET_BUILD_DIR=${TARGET_BUILD_DIR//" "/"\ "}

echo "Setting marketing version, CFBundleShortVersionString, to $VERSION in $TARGET_BUILD_DIR/$INFOPLIST_PATH..."

/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $VERSION" $TARGET_BUILD_DIR/$INFOPLIST_PATH

echo "Setting technical version, CFBundleVersion, to $BUILD in $TARGET_BUILD_DIR/$INFOPLIST_PATH..."

/usr/libexec/PlistBuddy -c "Set CFBundleVersion $BUILD" $TARGET_BUILD_DIR/$INFOPLIST_PATH

只要路径没有空格或特殊字符,这就可以正常工作。

以下是尝试调用此代码时发生的情况:

Setting marketing version, CFBundleShortVersionString, to 1.7.0.0 in /Users/jenkins/.jenkins/jobs/ClientName/jobs/iOS/jobs/What's Up/workspace/build/WhatsUp.app/Info.plist... File Doesn't Exist, Will Create: /Users/jenkins/.jenkins/jobs/ClientName/jobs/iOS/jobs/What Invalid Arguments

Setting technical version, CFBundleVersion, to 199 in /Users/jenkins/.jenkins/jobs/ClientName/jobs/iOS/jobs/What's Up/workspace/build/WhatsUp.app/Info.plist... File Doesn't Exist, Will Create: /Users/jenkins/.jenkins/jobs/ClientName/jobs/iOS/jobs/What Invalid Arguments

echo 可以很好地选择目录,但是 PlistBuddy 在尝试使用有问题的目录时返回错误。

到目前为止,我已经尝试了很多方法,例如使用“\”转义空格和特殊字符:

#replace spaces attempt
TARGET_BUILD_DIR=${TARGET_BUILD_DIR//" "/"\ "}
TARGET_BUILD_DIR=${TARGET_BUILD_DIR// /\ }

#replace apostrophes attempt
TARGET_BUILD_DIR=${TARGET_BUILD_DIR//"'"/"\'"}
TARGET_BUILD_DIR=${TARGET_BUILD_DIR//'/\'}

我需要做什么才能让 PlistBuddy 接受带有空格或特殊字符的目录?

最佳答案

事实证明,不需要替换空格和特殊字符。

@Etan Reisner 关于引用变量扩展的评论让我尝试了与此相关的各种其他事情。

引用 "$TARGET_BUILD_DIR""$INFOPLIST" 单独 成功了:

Setting marketing version, CFBundleShortVersionString, to $VERSION in $TARGET_BUILD_DIR/$INFOPLIST_PATH..."
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $VERSION" "$TARGET_BUILD_DIR"/"$INFOPLIST_PATH"

Setting technical version, CFBundleVersion, to $BUILD in $TARGET_BUILD_DIR/$INFOPLIST_PATH..."
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $BUILD" "$TARGET_BUILD_DIR"/"$INFOPLIST_PATH"

关于xcode - 处理 Xcode 构建阶段 Bash 运行脚本中的空格和特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36338031/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com