Subject: Re: Shell script for checking checksums
To: Jan Danielsson <jan.m.danielsson@gmail.com>
From: Jukka Salmi <j+nbsd@2006.salmi.ch>
List: netbsd-help
Date: 11/13/2006 18:40:52
Hi,

Jan Danielsson --> netbsd-help (2006-11-13 18:04:46 +0100):
[...]
>    Anyhow, a friend of mine told me that his Ubuntu system's md5sum can
> automatically check the checksums for him. I - on the other hand - to
> check them manually, which is deadly boring.

The cksum(1) tools shipping with NetBSD 4 and -current have a `-c
<file>' option which does what you want.


>    So I thought I would change that with the little shell programming I
> know. I came up with this:
[...]
>    This works fine -- as long as there are no spaces in the file name.
> Problem is -- I have lots of spaces in lots of file names. I understand
> that the problem lays in that "for l in <blah>" treats a space as a file
> name separator, and I am guessing that this is a design flaw which can
> not be worked around.

You could start by reading the checksum file line by line:

	while read line; do
		# now `$line' is the next line read from $1
	done <$1

To parse the md5(1) output, note that everything between the first
opening backet '(' and the last closing bracket ')' is the filename,
and the last word of the line is the checksum.


HTH, Jukka

-- 
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~