![引用 `find -execdir test [command]` 的命令(Bash)](https://linux22.com/image/1482231/%E5%BC%95%E7%94%A8%20%60find%20-execdir%20test%20%5Bcommand%5D%60%20%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%88Bash%EF%BC%89.png)
git fetch
如果有远程(=git remote
非空),我想在 git repos 中执行以下命令:
find -name .git -execdir test $(git remote) \; -execdir git fetch
^^^^^^^^^^^^^
How to quote/escape/mask this?
尝试了许多不起作用的变体,例如:"$(git remote)"
,,,,...'$(git remote)'
\$\(git remote\)
'"$(git remote)'"
答案1
尝试这个:
find -name .git -execdir sh -c 'test $(git remote)' \; -execdir git fetch \;
而且因为这无论如何都会启动一个 shell,你甚至可以执行以下操作:
find -name .git -execdir sh -c 'test $(git remote) && git fetch' \;