From owner-freebsd-questions@FreeBSD.ORG Thu Sep 20 11:28:15 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BF0B6106564A for ; Thu, 20 Sep 2012 11:28:15 +0000 (UTC) (envelope-from martin@dc.cis.okstate.edu) Received: from x.it.okstate.edu (x.it.okstate.edu [139.78.2.13]) by mx1.freebsd.org (Postfix) with ESMTP id 8FF098FC08 for ; Thu, 20 Sep 2012 11:28:15 +0000 (UTC) Received: from dc.cis.okstate.edu (localhost [127.0.0.1]) by x.it.okstate.edu (8.14.5/8.14.5) with ESMTP id q8KBSEGF037435 for ; Thu, 20 Sep 2012 06:28:14 -0500 (CDT) (envelope-from martin@dc.cis.okstate.edu) Message-Id: <201209201128.q8KBSEGF037435@x.it.okstate.edu> cc: FreeBSD Questions Date: Thu, 20 Sep 2012 06:28:14 -0500 From: Martin McCormick Subject: Re: bash Shell Scripting Question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Sep 2012 11:28:15 -0000 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.