I was trying to compute sha256 for a simple string, namely "abc". I found out that using sha256sum utility like this:
gives results identical to:
sha256sum # enter, to read input from stdin abc ^D
Note, that before the end-of-input signal another newline was fed to stdin.
What bugged me at first was that when I decided to verify it with an online checksum calculator, the result was different:
I figured it might have had something to do with the second newline I fed to stdin, so I tried inserting ^D twice this time (instead of using newline) with the following result:
Now, this is of course poorly formatted (due to the lack of a newline character), but that aside, it matches the one above.
After that, I realized I clearly fail to understand something about input parsing in the shell. I double-checked and there's no redundant newline in the file I specified initially, so why am I experiencing this behavior?
printf abc | sha256sum?
sha256sum filewhere file contains the actual
abc- very much is. And that's the method I used - with an actual file.
^Dis not actually sent, it just ends the stream.
sha256command (which they also explicitly mentioned in the code block).
strace sha256sumto see the
readsystem call it makes, and see what input you submit when you hit control-D on an empty line (creating a read()=0 meaning EOF) vs. a non-empty line (just submitting the line). (You can do this with
strace cat > /dev/nullas well. Similar to @user414777) Anyway, is that what this question is about?