shell script question
Erik Price
eprice at ptc.com
Mon Jan 20 12:29:44 EST 2003
bscott at ntisys.com wrote:
>
> First, a pet peeve of mine: Use
>
> for i in * ;
>
> instead of
>
> for i in `ls` ;
I always forget that it can be done that way, but in fact, in this case
I was ls'ing a diff't directory. I just posted a simplified version to
the list. Also, I recall from an earlier discussion on this list that
"find" is generally better to use in situations like this than "ls" but
"ls" takes less arguments, and I just wanted to quickly get an estimate
of a directory's disk usage, not write a true full-blown shell script.
I'll try to remember that I can glob instead.
> A corrected version of your original might be:
>
> for i in * ; do du -khs "$i" ; done
>
> The loop variable is placed in double-quotes to make sure the "du" command
> sees it as a single word. Otherwise, if one of your directories contained
> spaces or other shell meta-characters, it would get mangled by the shell
> before it got passed to "du". The rest of the command ("du" and "-khs")
> you want parsed as individual words so they get handled by the shell as the
> command to run and said command's arguments, respectively.
Good point.
> Hope this helps,
Yes it does. Thank you.
Erik
More information about the gnhlug-discuss
mailing list