使用包含带引号的codesign命令的变量查找-exec

时间:2016-09-01 07:27:59

标签: bash find exec sign codesign

我正在努力使查找-exec接受我的变量,其中包含带引号的命令......

signpath="codesign --force --deep --verbose --sign \"My Sign ID\""

然后无论我尝试找到什么版本的查找,我都无法成功执行$ signpath:

find "$pathtoframeworks" -type f -not -name '*.*' -exec "$signpath {}" \;
#the above results in codesign --force --deep --verbose --sign "My Sign ID" My App.app/Contents/Frameworks/MyFramework.framework/Versions/5/MyFramework: No such file or directory

find "$pathtoframeworks" -type f -not -name '*.*' -exec $signpath "{}" \;
#the above results in "My: no identity found

find "$pathtoframeworks" -type f -not -name '*.*' -exec "$signpath" {} \;
#the above results in codesign --force --deep --verbose --sign "My Sign ID": No such file or directory

查找-exec似乎无法处理变量中的引号...我该怎么办? :/

1 个答案:

答案 0 :(得分:2)

尝试单独引用:

find "$pathtoframeworks" -type f -not -name '*.*' -exec "$signpath" '{}' \;

虽然更好更安全的是在数组中保存命令行:

signpath=(codesign --force --deep --verbose --sign "My Sign ID")

并将其用作:

find "$pathtoframeworks" -type f -not -name '*.*' -exec "${signpath[@]}" '{}' \;