From owner-freebsd-questions@FreeBSD.ORG Tue Jun 16 15:02:38 2009 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 BB64610656D5 for ; Tue, 16 Jun 2009 15:02:38 +0000 (UTC) (envelope-from prvs=411319fdb=pauls@utdallas.edu) Received: from ip-relay-002.utdallas.edu (ip-relay-002.utdallas.edu [129.110.20.112]) by mx1.freebsd.org (Postfix) with ESMTP id 892418FC1B for ; Tue, 16 Jun 2009 15:02:38 +0000 (UTC) (envelope-from prvs=411319fdb=pauls@utdallas.edu) X-Group: RELAYLIST X-IronPort-AV: E=Sophos;i="4.42,229,1243832400"; d="scan'208";a="12579184" Received: from smtp3.utdallas.edu ([129.110.20.110]) by ip-relay-002.utdallas.edu with ESMTP; 16 Jun 2009 09:33:37 -0500 Received: from utd65257.utdallas.edu (utd65257.utdallas.edu [129.110.3.28]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp3.utdallas.edu (Postfix) with ESMTPSA id D26FC4EF47; Tue, 16 Jun 2009 09:33:37 -0500 (CDT) Date: Tue, 16 Jun 2009 14:33:37 +0000 From: Paul Schmehl To: Carmel NY , FreeBSD Questions Message-ID: <7F04C88B7C6A39C7E1B6F366@utd65257.utdallas.edu> In-Reply-To: References: X-Mailer: Mulberry/4.0.6 (Linux/x86) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=sha1; protocol="application/pkcs7-signature"; boundary="==========1E08F14CBC8E2C2B4973==========" X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: Re: Problem with bash script 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: Tue, 16 Jun 2009 15:02:39 -0000 --==========1E08F14CBC8E2C2B4973========== Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline --On Tuesday, June 16, 2009 08:09:09 -0500 Carmel NY =20 wrote: > > I am attempting to write a simple Bash script that will find all the > '*.pem' files in a directory structure and move them to another > directory. It seems to work until I get to the copy part where it fails. > > My scripting skills are not that good. Perhaps someone could tell me > what I am doing wrong. > > This is the script: > ># ! /usr/bin/env bash > ># Save the field separator > oIFS=3D$IFS > ># Set it to line breaks > IFS=3D$'\n' > > for i in $(find ./ -name "*.pem" -print); do > ># Get the basename > BN=3D$(basename $i) > ># copy the file to another directory using the base name > cp $i /usr/home/tmp/$BN > > done > ># Reset the IFS variable > IFS=3D$oIFS > > exit > When I write scripts, I test them on the commandline to see if they're doing=20 what I think they're doing. I don't get the $(find ....) construction. You're = invoking find from within a for loop to return a value. Use backticks. This works. for i in `find ./ -name "*.pem" -print` do foo bar done --=20 Paul Schmehl (pauls@utdallas.edu) Senior Information Security Analyst The University of Texas at Dallas http://www.utdallas.edu/ir/security/ --==========1E08F14CBC8E2C2B4973==========--