I am writing a POSIX shell script that may or may not receive input from stdin as in foo.sh < test.txt, non-interactively.
foo.sh < test.txt
How do I check whether there is anything on stdin, to avoid halting on while read -r line...?
while read -r line...
If I get the question right, you may try the following:
#!/bin/sh if [ -t 0 ]; then echo running interactivelly else while read -r line ; do echo $line done fi
2.1m questions
2.1m answers
60 comments
57.0k users