0

I have a file that has a list of bash commands like the following:

echo 'foobar'
echo 'helloworld'
echo 'ok'

And I can execute these commands by simply piping them to /bin/bash like so:

cat commands | /bin/bash

Now, how do I pause the execution right in the middle, and wait for the user input? Using read does not seem to work.

echo 'foobar'
echo 'helloworld'
read -p 'Press ENTER to continue'
echo 'ok'

1 Answers1

4

Execute like this:

/bin/bash commands

Piping the file to bash makes the file travel via stdin of bash. In such case read, reading from stdin, reads from the piped stream instead of from the terminal. It consumes echo 'ok'. By specifying the file as an argument to bash you still execute it, this time the stdin is not redirected though.

I assume you want to execute like this. Compare What is the difference between running bash script.sh and ./script.sh?