Date: Tue, 16 May 2006 10:58:49 +0200 From: Kyrre Nygard <kyrreny@broadpark.no> To: questions@freebsd.org Subject: Some shell scripts; a more elegant approach? Message-ID: <7.0.1.0.2.20060516105228.02238068@broadpark.no>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7.0.1.0.2.20060516105228.02238068>
