From owner-freebsd-questions Thu Mar 11 16:39:46 1999 Delivered-To: freebsd-questions@freebsd.org Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (Postfix) with ESMTP id CB3D215031 for ; Thu, 11 Mar 1999 16:39:41 -0800 (PST) (envelope-from ben@scientia.demon.co.uk) Received: from scientia.demon.co.uk (ident=ben) by scientia.demon.co.uk with local (Exim 2.12 #2) id 10LDbw-000DkT-00; Thu, 11 Mar 1999 22:07:24 +0000 (envelope-from ben@scientia.demon.co.uk) Date: Thu, 11 Mar 1999 22:07:24 +0000 From: Ben Smithurst To: Glen Mann Cc: questions@freebsd.org Subject: Re: find usage in shell script Message-ID: <19990311220724.A52801@scientia.demon.co.uk> References: <36E82CF2.F47BE244@cyberia.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.95.3i In-Reply-To: <36E82CF2.F47BE244@cyberia.com> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Glen Mann wrote: > Can somebody explain why I can do this on the command line > > find ./data -type f -exec chown nobody {} \; \ > -exec chgrp nogroup {} \; \ > -exec chmod 664 {} \; > > But not in a Bourne shell script? When I run the script with the backslashes > to break up the command to make it readable, I get this > > # ./fix_perms > find: : unknown option > -exec: not found > # > > Where is the second colon on the find: error line coming from? To get around > this, I have everything on a single line in the script, but that's not very > "pretty!" :) All I can think is that you have a space after one of the trailing backslashes in the shell script, or something. You might also need to quote the {}, though I'm pretty sure a) sh doesn't understand {a,b} things anyway, and b) shells that do leave {} alone because find uses it. So that probably isn't it. Incidentally, passing find's output into xargs might be more efficient. e.g. tmp=`mktemp _filenamesXXXXXX` || { echo mktemp failed; exit 1; } find ./data -type f > $tmp xargs chown nobody < $tmp xargs chgrp nogroup < $tmp xargs chmod 644 < $tmp rm $tmp Perhaps not as pretty, but your script will mean running three processes for each file found. Xargs will supply as many filenames as possible from the input, to the arguments of the specified command, without making the command line too long. -- Ben Smithurst ben@scientia.demon.co.uk send a blank message to ben+pgp@scientia.demon.co.uk for PGP key To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message