I would like a Bash script that can take input from a file or stdin, much like grep, for example
grep
$ cat
You got a typo here
read b < "${1-/dev/stdin}"
Try
read b < "${1:-/dev/stdin}"