My bash script (lets call it
myscript) takes input either from stdin (pipe), or form a regular file (if filename was provided as an argument)
a) someprog | myscript or b) myscript file.txt
Then, the data is processed line by line. At the moment, my code looks something like the following:
if [ -t 0 ] ; then while read LINE do prog_1 prog_2 ... prog_n done else while read LINE do prog_1 prog_2 ... prog_n done < $1 fi
This script works fine, but there seems to be too much duplicity. I am wondering whether there is a better (more elegant) way to do it. All the steps
n are the same. The only difference is whether there is a
< $1 at the end or not. is there no better way to do it?