problems using ls with for_in (SH)

Frank Shute frank at
Fri Nov 9 04:41:19 PST 2007

On Thu, Nov 08, 2007 at 11:49:24PM -0300, Sdvtaker wrote:
> Im trying to get a file with all the md5 hashes of one directory.
> My initial script was this:
> #!/bin/sh
> for file in $(ls)
> do
>        echo $file
>        md5 $file
> done
> The problem is with the file names who contains "whitespaces" becouse 
> the for_in passed each word as one iteration and not the full filename, 
> I'd tried using -B in ls, but doesnt help.
> Any idea what can i do?
> Thanks!
> Sdäv

You could use "find" which avoids the subdirs:

find . -maxdepth 1 -type f -print -exec md5 {} \;



 Contact info: 

More information about the freebsd-questions mailing list