gitman
gitman

Reputation: 31

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?

Upvotes: 3

Views: 596

Answers (1)

sehe
sehe

Reputation: 392833

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
...

Upvotes: 1

Related Questions