0

I was playing around with md5sum and redirections and I got a weird outcome.

I created an empty file name f1, and got this as its md5sum: d41d8cd98f00b204e9800998ecf8427e f1.

Then I used the command md5sum f1 > f1, and as I expected it, when I use cat f1, the same result appears on screen.

Keeping on, trying to set a loop, I then used md5sum f1, and the result was 1e3c66dfc03fbebc883b4718bf1bb065 f1 (so I'm sure I'm not in a special case where f(x)=x).

So I then typed md5sum f1 > f1, and when I used cat on the file, the content didn't change a bit (it was still d41d8cd98f00b204e9800998ecf8427e f1 and not 1e3c66dfc03fbebc883b4718bf1bb065 f1 as it should be). So I thought that I was missing something with feed redirection (I'd like to point I'm not trying to have successives sums in the file, but only the last one computed), so I tried echo foobar > f1 and cat f1 gave me the expected foobar.

Do you have any idea why the new md5sum isn't in the file?

If this can help, I'm running Ubuntu version 18.04.4 and md5sum version 8.28

Thanks

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
Tloz
  • 113
  • 5
  • So based on the second answer of your link, I should use `md5sum f1 | sponge f1`. Well, if you want to post your comment as an answer, I will accept it, as you enlighted me. Thanks – Tloz May 08 '20 at 20:44
  • I think it's probably better to mark it a duplicate; this problem comes up in a wide variety of situations, but it's really the same core thing (i.e. how shell output redirection works) so I think it's better to have one *good* answer (/collection of answers) and just refer to that in the other situations it comes up. – Gordon Davisson May 08 '20 at 21:38

0 Answers0