Why does cp a b result in error when cp a b > a results in no error when neither a nor b file exists.
From my understanding cp a b gives error because neither file exists, makes sense and cp a b >a seems to create both files and copy blank from b to a but the reason a is empty is because output of the operation does not actually produce any messages.
Please let me know what the correct explanation is. Thanks
When you invoke
cp a b > a
, the first thing the shell does is create the filea
. It then creates a child and redirects its output to that file before the child execscp
. Soa
exists beforecp
starts, and it happily copies the file.