I’ve written a small script in bash that parses either the provided files or stdin if no file is given to produce some output. What is the best way to redirect the parsed output to stdout (at the end of the script the result is stored in a variable). Should I use cat or echo, or is there another preferred method?
I’ve written a small script in bash that parses either the provided files or
Share
Use the
printfcommand:echois ok for simple cases, but it can behave oddly for certain arguments. For example,echohas a-noption that tells it not to print a newline. If$varhappens to be-n, thenwon’t print anything. And there are a number of different versions of
echo(either built into various shells or as/bin/echo) with subtly different behaviors.