我正在努力让 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[@]}" '{}' \;
关于bash - find -exec 的变量包含带有引号的 codesign 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39265285/