I am making a script that is taking input via a pipe (stdin), as in (other_command | my_script). However, I need to pause the script and wait for the user to press enter, after I have read the whole stdin.
Here is an example-script.
#!/bin/bash
if [[ -t 0 ]]; then
echo "No stdin"
else
echo "Got stdin"
while read input; do
echo $input
done
fi
echo "Press enter to exit"
read
And it works like this;
$ echo text | ./script
Got stdin
text
Press enter to exit
$
It jumps over my final read.
However;
$ ./script
No stdin
Press enter to exit
stops here
$
How can I get the read to work after I have read from stdin? And is there a solution that would work on both Linux and OSX?