开发者

git submodule foreach: execute read

Is it possible to execute a read inside a git foreach?

git开发者_如何转开发 submodule foreach 'read -p "test"; echo $REPLY'

does not work at all as the read gets the input from git itself - which is the objname and hash here. Is there any chance to read interactively of the console?


You can if you redirect input/output to /dev/tty. You will want to check whether a tty is available with isatty based methods first when you do this kind of thing.

E.g., create a ./test.sh like so

exec </dev/tty >/dev/tty
read -p "Enter text:" VALUE
echo "got: $VALUE"

And then

git submodule foreach ../test.sh

Will do the right thing, e.g. in my testing

sehe@meerkat:~/custom/MONO$ git submodule foreach ../test.sh
Entering 'cecil'
Enter text:a
got: a
Entering 'glib'
Enter text:b
got: b
Entering 'gtk-sharp'
Enter text:c
got: c
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜