@Paul: Yeah, it may be too late for me to switch at this point, but perhaps I'll give zsh
another look.
I am familiar with -M
and its cousins, but that doesn't do the same thing as -ot
/-nt
. -M
compares a file time to the script time, whereas -ot
compares two arbitrary files (one of which could be $0
if you like).
Good tip on the globbing angle brackets tho ... I'd never thought about the possibility that they might do tilde expansion.
@butteredham: Yeah, I think that pretty much sums up how I feel as well.
@Joel: You know, I've glanced at the Zoidberg docs many times, but never actually taken it out for a spin. Perhaps I'll give it a shot. Thanx for the tip!
]]>For options parsing, I use a block similar to the following that I just copy-n-paste to pretty much every bash
script I write:
readonly me=${0##*/} # slightly prettier than $0
partial=0
while getopts ':iph' opt
do
case $opt in
p) partial=1 # partial matches are the default for locate
;;
i) ignore_case='-i'
;;
h) echo "usage: $me -h | [-ip] dirname" >&2
echo " -i : ignore case when matching dirname" >&2
echo " -p : partial match on dirname" >&2
echo " -h : this help message" >&2
echo " colnum : column of numbers to add (non-numeric values in this col treated as 0)" >&2
exit
;;
:) echo "$me: $OPTARG requires an argument ($me -h for help)" >&2
exit 2
;;
\?) echo "$me: unknown argument $OPTARG ($me -h for help)" >&2
exit 2
;;
esac
done
shift $(( $OPTIND - 1 ))
Now, admittedly, this only deals with short (stackable) flags, but that's generally good enough for me. I'm an old-school *nixite who believes that ls
as an abbreviation for "list" was a good idea. :-D
]]>
# initialize variables
{
local $/ = "\n\n";
# read file here
}
# process the data here
It is a shame that per-filehandle record separators are not supported. (IO::Handle allows you to control quite a lot of stuff on a per-filehandle basis, such as autoflush, but not the record separator.) It is a shame that $/ cannot be lexicalised (like $_ can).
Ultimately the lesson from this is that whenever you want to read from a file, if you care about the record separators at all, then you need to do local $/ = ...
, even if you just want the default separator, because you never know what your caller has done.
Clearly this module you're using is not doing that. It should. File a bug report.
]]>Thanks Buddy.
~Dinesh
]]>run some command | while read line do process each "$line" done]]>