[PATCH] Fancy rc startup style RFC

Brooks Davis brooks at one-eyed-alien.net
Wed Apr 19 17:06:48 UTC 2006


On Wed, Apr 19, 2006 at 05:57:21PM +1000, Peter Jeremy wrote:
> On Tue, 2006-Apr-18 15:02:27 -0500, Eric Anderson wrote:
> >Peter Jeremy wrote:
> >>>+	padding=""
> >>>+	paddingsize=$(($columns - 15 - $2 - $namesize))
> >>>+	until [ 0 = ${paddingsize} ]; do
> >>>+		padding=" $padding"
> >>>+		paddingsize=$(($paddingsize - 1))
> >>>+	done
> >>
> >>This particular block of code appears unnecessary (since $padding is 
> >>unused).
> >
> >I must be missing something, because I'm pretty sure it's used.. What 
> >did I miss?
> 
> Actually, I had a closer look and I was wrong, sorry.  I missed the
> '[ $2 = 0 ]' test.  The code might be more legible (and is definitely
> more efficient) if the above code was moved into the else clause for
> that test.
> 
> Also '[ $2 = 0 ]' should probably be written as '[ "0$2" -eq 0 ]', or
> similar, so that it doesn't blow up if there is no $2.

Or better use "${2:-0}" if that's what you mean.  The idiom of
prepending stuff to a variable in a string to deal with the unassigned
variables has always seemed to me like it was a hold over from some
truly ancent shell without modern features.  The '[ "x$var" = "x" ]'
idiom is even worse.  Test has only had -z and -n for a decade or two...

-- Brooks

-- 
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20060419/07e7d81b/attachment.pgp


More information about the freebsd-hackers mailing list