我正在努力使查找-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似乎无法处理变量中的引号...我该怎么办? :/
答案 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[@]}" '{}' \;