In bash, can I somehow get rid of the cat
part (and the fork it brings) in the following command line?
cat >some_file
Use process-substitution in bash
, to avoid useless-use-of-cat
> file
while IFS= read -r line
do
printf "%s\n" "$line"
done < /dev/stdin >> file
To read form stdin
and append to the file
on the run, > file
truncates the contents of the file before reading starts.
Including this suggestion from Leon's comment for a one-line option to do this,
while IFS= read -r line; do echo "$line"; done > file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With