Hi,
Anthony Coulter <[email protected]> writes:
> Some of the system scripts make inconsistent use of ksh-specific
> features, specifically "print" and "[[" as efficient replacements for
> "echo" and "[". This change makes the /etc/ksh.kshrc and all the rc
> scripts use "print" and "[[" exclusively.
You don't explain why `print' is more efficient than `echo'.
> Switching from echo to print only brought up one interesting issue:
> /etc/rc.d/mountd uses "print -n >foo" instead of "touch foo".
> The latter is arguably more transparent but I didn't change to it.
>
> Switching from [ to [[ makes a lot of things more readable; most of
> the improvements result from removing unnecessary quotation marks.
I'm not sure I see how it makes things more readable; less bytes on the
screen? Most contexts where variables are involved should use quotes
anyway. So I am not sure this is a good thing in the end.
> We also don't have to test for unset variables as aggressively; a
> number of awkward [ X"$foo" = XYes ] constructions were replaced
> with [[ $foo = Yes ]] .
This is not related to quote removals. AFAIK ksh handles [ "$foo" = Yes ]
properly, the "X"s aren't necessary. They were probably added because
of horror stories about ancient shells.
> The test [[ ${_args} = "${_args# }" ]] appears in rcctl; I left the
> quotation marks on the right-hand side because I'm afraid of breaking
> something I don't understand.
FWIW I can't see why removing the quotes would break anything here.
> The rcctl script also has a lot of lines like:
> daemon_timeout="$(svc_getdef ${_svc} timeout)"
> I think the quotation marks are unnecessary but the original author
> went to a lot of trouble to escape internal quotes, e.g.
> daemon_flags="$(eval print \"\${${_svc}_flags}\")"
The "internal" quotes are escaped so that they are still present after
the `eval' pass, not because the whole command substitution itself is
surrounded by double quotes.
var='a b'; eval print "\$var"; eval print \"\$var\"
> so I'll give him the benefit of the doubt. I would encourage somone
> with greater confidence to take a closer look.
>
> I replaced `backticks` with $(subshell notation) in a few places, but
> only in places where I was already changing [ to [[. I wanted to remove
> them all but I can't really justify the change in terms of either
> readability or process efficiency.
While I prefer using $() in my scripts, this looks like needless
churn. The diff doesn't simplify a single instance of nested ``-style
command substitutions.
> Regarding numeric changes: in ksh, [[ 0 -eq 00 ]] is true (numeric
> comparison) but [[ 0 = 00 ]] is false (string comparison). The latter
> is more readable,
This sounds like a personal preference. I prefer to use numeric
operators when dealing with numbers.
> so I made the switch in places where the left-hand
> side is a system output, e.g. [[ $(id -u ) = 0 ]] or [[ $# > 0 ]].
> I would not expect id(1) to print the string "00" for root, nor would
> I expect the shell to print "00" for $#. But I did *not* change
> comparison operators in more complicated situations, like the bottom
> of /etc/rc which has [[ ${daemon_rtable} -eq 0 ]]. It isn't immediately
> obvious what sort of string is in ${daemon_rtable} so the numeric
> comparison seems appropriate here.
>
> I corrected a comment at the top of /etc/rc; it said that "set +o sh"
> turned Strict Bourne shell mode off. I'm pretty sure it's actually
> turning strict mode on.
Nope, ''set -o sh'' sets strict mode on, ''set +o sh'' disables it.
[...]
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE