Hey all,

I have a dumb question to ask :(..

I want to know how to create a shell script that reads input from the STDIN as default, but when [-o inputFile] is entered as an option, it will read the input from the inputFile. I want to do this in a way that doesn't need to duplicate code for each case....

Thank you so much for your help.. Regards...

Recommended Answers

All 2 Replies

Hey all,

I have a dumb question to ask :(..

I want to know how to create a shell script that reads input from the STDIN as default, but when [-o inputFile] is entered as an option, it will read the input from the inputFile. I want to do this in a way that doesn't need to duplicate code for each case....

case $1 in
     -o) shift ;;
     *)  set -- /dev/stdin ;;
esac

while IFS= read -r
do
  : do whatever with "$line"
done < "$1"

Thank you so much that really helped!...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.