Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Don't use csh for scripting!' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Don't use csh for scripting!
Authored by: a1291762 on Apr 16, '02 09:43:09PM

Go and look at http://www.gregor.com/dgregor/csh_whynot.html for why you shouldn't be using csh for scripting.

Here's my version (using bourne shell programming of course) that's even more fancy. (Replace <BACKSLASH> with a backslash)

#!/bin/sh
# mdiff:
# Provides the equivalent of 'diff' for comparing files
# that use the traditional Macintosh line ending: r

# So people don't make weird versions of printf, diff, rm etc. run
PATH=/bin:/usr/bin:$PATH

# Print the usage and exit
usage()
{
diff -h
printf "Usage: %s [ -bcefhintwlrs ] file1 file2" `basename $0`
exit 2;;
}

# Cleanup when exiting
cleanup()
{
rm "$ufile1" "$ufile2"
exit;
}

# pass on arguments to diff except for h (print help)
while getopts bcefhintwlrs arg; do
case $arg in
<BACKSLASH>?) usage;;
h) usage;;
?) args="$args -$arg";;
esac
done
shift `expr $OPTIND - 1`

# We need 2 arguments
[ $# -ne 2 ] && usage
mfile1="$1"
mfile2="$2"

# We create temporary files ufile1 & ufile2 with r changed to n
ufile1="/tmp/mdiff$$.1"
ufile2="/tmp/mdiff$$.2"
tr "r" "n" <"$mfile1" >"$ufile1"
tr "r" "n" <"$mfile2" >"$ufile2"

# Remove the temporary files when exiting (via Ctrl+C or normal exit or kill etc.)
trap "cleanup" 0

# Do the diff
diff $args "$ufile1" "$ufile2"



[ Reply to This | # ]