NOTE - this answer solved my issue: https://unix.stackexchange.com/a/29698/110877I'm writing a simple bash function to remove duplicate lines in a file:rdups() {    sort -u $1 > $1}I have a file, garbage.txt, whose contents look like:this is a testfood that are killing youwings of firewe hope that the labor spent in creating this softwarethis is a testunix ips as well as enjoy our blogAfter I run this function as such:rdups garbage.txtI would expect garbage.txt to contain:food that are killing youthis is a testunix ips as well as enjoy our blogwe hope that the labor spent in creating this softwarewings of fire(i.e. sorted, and with duplicate lines removed.)However, I find that garbage.txt is empty instead. If I modify the function as such:rdups() {    sort -u $1 > no-dups.txt}no-dups.txt contains the output I would expect.I'd prefer to overwrite the file from which I'm removing duplicates, which I know I can accomplish using temporary files. But I'm also curious why when redirecting to the same file as used as input, the file's contents are cleared.
Why does redirecting output to file used as an argument clear its contents?
bash;files