bash Shell Scripting Question

Martin McCormick martin at
Thu Sep 20 11:28:15 UTC 2012

Many thanks! The for loop was what was needed.

Polytropon writes:
> Just a sidenote: If you're not using bash-specific functionality
> and intend to make your script portable, use #!/bin/sh instead.

I always start out that way for that very reason. I needed some
random number functions and arithmetic for another part of the
script so I ended up going to bash.

> > while read dirname; do
> Attention: "dirname" (/usr/bin/dirname) is a binary!

You are so correct!  Thank you.


> Correct. You could use different approaches which may or may
> not fail due to the directory names you will encounter (like
> directories with spaces or special characters).

In this application, all the directories will be
non-problematic, but point well taken.

>         #!/bin/sh
>         for DIR in `ls -LF | grep \/`; do
>                 cd ${DIR}
>                 # do stuff
>         done

That works perfectly. Again many thanks.

More information about the freebsd-questions mailing list