Bash: Is it ok to use same input file as output of a piped command?
Posted
by Amro
on Stack Overflow
See other posts from Stack Overflow
or by Amro
Published on 2010-06-16T15:56:39Z
Indexed on
2010/06/16
21:22 UTC
Read the original article
Hit count: 243
Consider something like:
cat file | command > file
Is this good practice? Could this overwrite the input file as the same time as we are reading it, or is it always read first in memory then piped to second command?
Obviously I can use temp files as intermediary step, but I'm just wondering..
t=$(mktemp)
cat file | command > ${t} && mv ${t} file
© Stack Overflow or respective owner