Git submodule foreach: perform read

Is it possible to read inside git foreach?

git submodule foreach 'read -p "test"; echo $REPLY'

doesn't work at all, as reading gets input from git itself, which is an objname and hash object here. Is it possible to read the console interactively?

+3
source share
1 answer

You can redirect input / output to /dev/tty. You will want to check if tty is accessible by isattymethods when you do such things.

For example, create ./test.shlike this

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

And then

git submodule foreach ../test.sh

You will do the right thing, for example. 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
...
+1
source

All Articles