From owner-freebsd-questions@FreeBSD.ORG Tue May 16 08:58:48 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 81A2816A43E for ; Tue, 16 May 2006 08:58:48 +0000 (UTC) (envelope-from kyrreny@broadpark.no) Received: from osl1smout1.broadpark.no (osl1smout1.broadpark.no [80.202.4.58]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9D7E343D6D for ; Tue, 16 May 2006 08:58:45 +0000 (GMT) (envelope-from kyrreny@broadpark.no) Received: from osl1sminn1.broadpark.no ([80.202.4.59]) by osl1smout1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0IZC00AZGOXWZMF0@osl1smout1.broadpark.no> for questions@freebsd.org; Tue, 16 May 2006 10:58:44 +0200 (CEST) Received: from urban.broadpark.no ([80.203.212.30]) by osl1sminn1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0IZC00J2JOXVBEI0@osl1sminn1.broadpark.no> for questions@freebsd.org; Tue, 16 May 2006 10:58:44 +0200 (CEST) Date: Tue, 16 May 2006 10:58:49 +0200 From: Kyrre Nygard To: questions@freebsd.org Message-id: <7.0.1.0.2.20060516105228.02238068@broadpark.no> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 7.0.1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT Cc: Subject: 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 08:58:49 -0000 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 mv -f $file $file.tmp tr -d '\r' < $file | cat -s | sed -E -e 's/[[:space:]]+$//' > $file.tmp echo > blank echo >> $file.tmp cat blank $file.tmp >> $file rm -f blank $file.tmp done 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 * echo "Setting files to $3, folders to $4." find -s . -type f -exec chmod $3 '{}' \; find -s . -type d -exec chmod $4 '{}' \; -- 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