PySIG Notes, 22-May-2008
Kevin D. Clark
kevin_d_clark at comcast.net
Thu May 29 14:24:43 EDT 2008
Ted Roche writes:
> Sample Gotcha: scripts with a she-bang line might not always be
> transportable between Windows, Unix and OS X because of line ending
> differences. If your parser complains about invalid commands on the
> she-bang line, make sure your line endings are correct for the
> platform.
I've had quite a few not-hugely-technical co-workers run into this
exact problem over the years. In order to help them out I've written
the following alias (dostxtfind), which allows me to find the suspect
files quickly.
I include another alias (txtfind) because this is frequently useful as
well.
# txtfind, dostxtfind, and binfind all use Perl's -B and -T file
# test operations.
#
# Here are some relevant sections from the perlfunc documentation:
#
# The "-T" and "-B" switches work as follows. The first block or
# so of the file is examined for odd characters such as strange
# control codes or characters with the high bit set. If too many
# strange characters (>30%) are found, it's a "-B" file, other-
# wise it's a "-T" file. Also, any file containing null in the
# first block is considered a binary file.
# ...
# Both "-T" and "-B" return true on a null file.
#
# Caveat programmer.
txtfind () {
if [ $# -eq 0 ] ; then
txtfind .
else
perl -MFile::Find -e 'find(sub{print "$File::Find::name\n"
if (-f && -T);}, @ARGV);' "${@}"
fi
}
dostxtfind () {
if [ $# -eq 0 ] ; then
dostxtfind .
else
perl -MFile::Find -e 'find(sub{
$crlf = 0;
$f = -f;
$T = -T;
@ARGV=($_);
binmode(ARGV);
((/\r\n/) && $crlf++) while(<>);
print "$File::Find::name $crnl\n"
if ($f && $T && $crlf);
}, @ARGV)' "${@}"
fi
}
Kind regards,
--kevin
--
GnuPG ID: B280F24E I blew the weathervane
alumni.unh.edu!kdc off some old roadhouse...
http://kdc-blog.blogspot.com/ -- Tom Waits
More information about the gnhlug-discuss
mailing list