3 ms·
The first example has a lot more use cases than it alludes to. I have a lot of aliased utility scripts for text processing, and frequently need to use them over
by cosmie 10y ago
The first example has a lot more use cases than it alludes to. I have a lot of aliased utility scripts for text processing, and frequently need to use them over entire files as well as on output piped from other processes. In this case, I don't know if the input file is going to be an argument or stdin from some upstream operation. That's easily taken care of with
INPUT_FILE="${1:-/dev/stdin}"
Which sets the input to the first argument if there is one, or stdin if there isn't. My solution was a lot messier before I learned about parameter substitution.