我正在使用以下作为 git shell 脚本。
#!/bin/sh
[ -z "$1" ] && dir="$PWD" || dir="$1"
find "$dir" -mindepth 1 -maxdepth 1 -type d -exec sh -c '
for i; do
printf "\n%s\n" "$i"
cd "$i" \
&& git remote update
done' sh {} +
但想使用 git 别名。
rmup=!sh -c "find . -mindepth 1 -maxdepth 1 -type d -exec sh -c '\
for i; do \
printf "\n%s\n" "$i" && cd "$i" && git remote update; \
done' sh {} +"
或者至少是一个 shell 别名。
alias rmup="find . -mindepth 1 -maxdepth 1 -type d -exec sh -c '\
for i; do \
printf "\n%s\n" "$i" && cd "$i" && git remote update; \
done' sh {} +"
我尝试了各种转义、单引号和双引号组合,但都没有成功。
想要使用“嵌入式”别名的原因是为了简化机器之间的维护和可移植性,因为我已经同步了我的 .gitconfig
和 .bashrc
。
忘了说我也试过 shell 函数,当 printf
打印目录时,cd
提示目录不存在。
rmup() {
find . -mindepth 1 -maxdepth 1 -type d -exec sh -c '
for i; do
printf "\n%s\n" "$i" && cd "$i" && git remote update;
done' sh {} +
}
最佳答案
如果你已经有了 shell 脚本,那么将它命名为 git-rmup
,把它放在你的 $PATH
中,你就可以调用 git rmup
就好像它是一个 Git 别名。
关于linux - 如何在 git 或 shell 别名中使用 `find -exec sh -c`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30408006/