Create md5sums for easy shell usage # $Header: /CVSROOT/md5chk/DESCRIPTION,v 1.5 2007-01-17 01:19:12 tino Exp $ # # $Log: DESCRIPTION,v $ # Revision 1.5 2007-01-17 01:19:12 tino # Options -s and -d # # Revision 1.4 2006/07/31 21:24:05 tino # Documentation clarified (was buggy) and help (-h) improved # # Revision 1.3 2006/07/25 21:54:22 tino # See ChangeLog # # Revision 1.2 2006/07/25 21:31:33 tino # release 0.0.0 # # Revision 1.1 2006/07/25 20:56:18 tino # First version Sometimes you want to pipe a list of files to md5sum. This then looks like
find . -type f -print0 |
xargs --null md5sum -b -- |
while read a b
do ...
The problem is that the $b then starts with a * and you don't know what happens if the filename contains nonstarndard characters like LF. Some md5sum dialects just create garbage, others escape the MD5 sum. md5chk doesn't do this and was designed from ground up for bash usage. It guarantees that the md5 sum always is "clean" and the filename always is properly escaped for shell reads. Note that there is no way for shell reads to express the newline character nor spaces at the end of an argument. So an unescape via ANSI strings must be done, sorry.
find . -type f -print0 |
md5chk -n |
while read -r md5 name
do
	eval name="\$'$name'"
	...
Note that the "eval" line does the escape entirely runs in the shell and thus is very fast. Another common usage is "create md5 string from a file":
md5="`md5chk -iq "$name"`"; echo $?
Now you can create an md5sum from argument directly, too:
md5="`md5chk -dq "$string"`"