Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "getopts" bugs and bad interactions with "shift"



On Nov 24, 12:50pm, Sven Wischnowsky wrote:
} Subject: Re: "getopts" bugs and bad interactions with "shift"
}
} Bart Schaefer wrote:
} 
} > ...
} > 	shift $OPTIND	# $((OPTIND-1)) if 3.0.7 or before
} > ...
} > 	return $ret
} 
} I think, when *you* do this kind of stuff, you have a good reason, so:
} why the `$'s (and even `$((...))')? Compatibility with other shells?

Compatibility with my brain, is more like it.

When re-reading a script, I like being able to tell, without having to
think about the context, whether a string is just a string, or is the
name of a parameter.  I've never particularly liked the feature that
you can omit the $ in math context, though it almost makes sense in the
case of $[foo] and $((foo)) to not need $[$foo].  ("Almost" because of
this:

zagzig[21] setopt nounset
zagzig[22] echo $foo   
zsh: foo: parameter not set
zagzig[23] echo $[foo]
0

I hate not being able to use nounset to detect typographical errors in
parameter names.)

To a lesser extent, it's defensive programming in the sense that if I
don't get used to leaving off the $ in zsh scripts then I won't forget
to use it in plain sh scripts.

Finally, it means I don't have to remember where zsh uses math context
and where it doesn't; and the less I have to remember, the better.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author