Strange symbols at the end of md5sum Strange symbols at the end of md5sum unix unix

Strange symbols at the end of md5sum


When you use md5sum to calculate a MD5 hash from stdin (standard in) it outputs - as the filename. For example,

$ md5sum hello.cff585184df1b2b93e8e67058e1e708c4  hello.c$ md5sum < hello.cff585184df1b2b93e8e67058e1e708c4  -

Note that the second command reads from stdin while the first reads directly from hello.c

If you don't want the filename, you could pipe the output to awk - like

$ md5sum < hello.c | awk '{print $1}'ff585184df1b2b93e8e67058e1e708c4

Or, for your specific case,

UUID="$(echo -n "$timestamp" | md5sum | awk '{print $1}')"

Or,

UUID="$(printf $timestamp | md5sum | awk '{print $1}')"


In UNIX land, - is often a placeholder filename meaning "standard input" or "standard output". In this case it means standard input, because you piped data into md5sum.


Instead of echoing the result use printf perhaps, and set the maximum length:

printf "%.32s\n" "$UUID"

Since md5 is always 32 characters long using a format string should work.