Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 977
gitman Avatar asked Mar 02 '26 08:03

gitman


1 Answers

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
...
like image 111
sehe Avatar answered Mar 03 '26 23:03

sehe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!