From owner-freebsd-questions@FreeBSD.ORG Tue May 16 15:59:31 2006 Return-Path: X-Original-To: questions@freebsd.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4070616A573 for ; Tue, 16 May 2006 15:59:31 +0000 (UTC) (envelope-from atom.powers@gmail.com) Received: from nz-out-0102.google.com (nz-out-0102.google.com [64.233.162.207]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2CF9D43D78 for ; Tue, 16 May 2006 15:59:23 +0000 (GMT) (envelope-from atom.powers@gmail.com) Received: by nz-out-0102.google.com with SMTP id n1so183099nzf for ; Tue, 16 May 2006 08:59:23 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=hj4oMn0IlxNkTzmN/8RqIQxkZXT/4n9PM1nMu0xTyOjqnOwv10+IDZKsen3HXjWh6OoMcyfYx8K4zjXpIJYfvqOdLUDfdIPdv+IP600WxmvdqeDgHnzEhqCVMgooLGCduDjj+4esGJsvIbqaJV6AEAMebhf6TTg9fpi9tKCUmRI= Received: by 10.64.3.9 with SMTP id 9mr1083179qbc; Tue, 16 May 2006 08:59:23 -0700 (PDT) Received: by 10.65.150.9 with HTTP; Tue, 16 May 2006 08:59:23 -0700 (PDT) Message-ID: Date: Tue, 16 May 2006 08:59:23 -0700 From: "Atom Powers" To: "Kyrre Nygard" In-Reply-To: <7.0.1.0.2.20060516105228.02238068@broadpark.no> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <7.0.1.0.2.20060516105228.02238068@broadpark.no> Cc: questions@freebsd.org Subject: Re: Some shell scripts; a more elegant approach? 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 May 2006 15:59:35 -0000 It is difficult to understand exactly what you want your script to do without comments. You may get a better response if you can describe what you want your scripts to do. On 5/16/06, Kyrre Nygard wrote: > > Hello! > > I have a bash script here to clean .txt files. > > But I want to incorporate a feature where, if the .txt file is > less than 300 bytes, it will echo "$file: Corrupt". > > I'm very new to scripting, but I know that this method is not really nice= : > > -- > > for file in `find -s . -type f -name "*.txt"`; do > This line is redundant, if you ">| $file.tmp" below. (or if you turn "noclobber" off for your shell) > mv -f $file $file.tmp > > tr -d '\r' < $file | cat -s | sed -E -e 's/[[:space:]]+$//' > $fi= le.tmp > I don't see why you need an empty file here. > echo > blank This line doesn't do anything. > echo >> $file.tmp > why not just "mv $file.tmp $file"? > cat blank $file.tmp >> $file > > rm -f blank $file.tmp > > done > You should probably do this on the .tmp file before you overwrite the origi= nal. > for file in `find . -type f -name "*.txt" -size -300c`; do > > echo "$file: Corrupt" > > done > > -- > > I also have another script here that I'm wondering some about: > > -- > > echo "Giving files to user $1, group $2." > > chown -R $1:$2 * > if [ $3 -a $4 ] ; then > echo "Setting files to $3, folders to $4." > > find -s . -type f -exec chmod $3 '{}' \; > find -s . -type d -exec chmod $4 '{}' \; > fi > -- > > It mass sets permissions and ownerships. > > In it, I have to specify $1, $2, $3 and $4. If I just specify let's say > $1 and $2, it will error out because the finds in $3 and $4 aren't > given anything. > > How do I avoid this? > > Thanks people, I apologize for my ignorance, > > -- Kyrre > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o= rg" > --=20 -- Perfection is just a word I use occasionally with mustard. --Atom Powers--