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
1.4m articles
1.4m replys
5 comments
57.0k users