bash - find -exec 的变量包含带有引号的 codesign 命令

标签 bash find exec sign codesign

我正在努力让 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/

相关文章:

linux - 杂乱和重复的输出

bash - 打印正确的 MHz 或 GHZ 数字取决于 CPU 缩放

matlab - 找到连续的非零值

linux - 如何从 shell 脚本内部更新 shell 脚本

C-execl() : can't execute file located in another directory

python - 在 Go 项目文件夹中运行 python 脚本(使用脚本的项目/相对文件路径)

c - C 语言中的 int main() 返回一个 int 但 shell 只接受 unsigned char

linux - 在后台运行 heredoc 格式的脚本?

通过 exec 对 find 的输出进行 Bash 变量替换

linux - git 在多个文件名和文件夹名中查找并重命名一个字符串