0

i am using read -p "Press any key to continue" in my script. This works fine except when it is in a while loop like

while read TEST_NAME  ; do
    read -p "Press any key..."
    echo "Executing:"
done <$MT_TEST_ROOT_DIR/automation.mts

i am suspecting it is because of the enclosing while looping doing the read as well. so what would be the solution for it

Vik
  • 8,721
  • 27
  • 83
  • 168

2 Answers2

1

The issue is indeed the enclosing redirection. You can simply redirect the inner read input from /dev/tty (your keyboard) that way:

while read TEST_NAME  ; do
    read -p "Press any key..." < /dev/tty
    echo "Executing:"
done <$MT_TEST_ROOT_DIR/automation.mts
jlliagre
  • 29,783
  • 6
  • 61
  • 72
0

Both reads are reading from the same input file. Use a different file descriptor for the first read, letting the second read inherit whatever your script is using.

while read TEST_NAME <&3  ; do
    read -p "Press any key..."
    echo "Executing:"
done 3< "$MT_TEST_ROOT_DIR"/automation.mts
chepner
  • 497,756
  • 71
  • 530
  • 681