Date: Thu, 20 Sep 2012 06:28:14 -0500 From: Martin McCormick <martin@dc.cis.okstate.edu> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: bash Shell Scripting Question Message-ID: <201209201128.q8KBSEGF037435@x.it.okstate.edu>
next in thread | raw e-mail | index | archive | help
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. Continuing; > 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209201128.q8KBSEGF037435>