0

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...

2
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by blackrobe
0

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"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.