find -exec 带有一个包含带引号的协同签名命令的变量

find -exec with a variable containing a codesign command with quotes

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

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

然后无论我尝试什么版本的 find,我都无法成功地正确执行 $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

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

尝试单独引用它:

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[@]}" '{}' \;