Date: Thu, 11 Mar 1999 22:07:24 +0000 From: Ben Smithurst <ben@scientia.demon.co.uk> To: Glen Mann <gmann@cyberia.com> Cc: questions@freebsd.org Subject: Re: find usage in shell script Message-ID: <19990311220724.A52801@scientia.demon.co.uk> In-Reply-To: <36E82CF2.F47BE244@cyberia.com> References: <36E82CF2.F47BE244@cyberia.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990311220724.A52801>