RHAT bug? /etc/init.d/functions:daemon()
Ben Scott
dragonhawk at gmail.com
Tue Jan 31 16:34:01 EST 2006
On 1/31/06, Michael ODonnell <michael.odonnell at comcast.net> wrote:
> A couple of questions; first, does anybody else have a
> recent RHAT EL4 system ...
I don't have one of those.
> in /etc/init.d/functions starts out with this line:
>
> while [ "$1" != "${1##[-+]}" ]; do
>
> ...and second, can anybody explain the alleged logic?
Based on the entire function, it looks like they're shooting for
some kind of command-line option parsing. If I read that right, the
construct
${1##[-+]}
returns the parameter $1 with any leading plus (+) or minus (-)
character stripped off. So if the parameter begins with one of those,
the resulting stripping will not match the unstripped parameter, and
the "not equal" comparison will be true, causing the enclosed case
block to execute. If the parameter does not begin with one of those
special characters, there is nothing to strip, so the "stripped"
expansion is equal to the regular expansion, the "not equal" test
fails, and the while drops out and proceeds on in the function.
I had to look up the parameter expansion syntax in the bash(1)
manual, because I rarely use it. So I may be wrong here (more then
usual, I mean).
The case block appears to contain a handful of options which effect
how the "daemon" function behaves.
> I claim it can NEVER evaluate true because $1 is always the
> name of the daemon you want launched ...
Well, no, not if you're doing something like
daemon --user nobody blahd
which the case block implies you can do.
> I wrote a daemon that I intend to execute at low priority
> and hoped to use that daemon function to launch it, but it's
> never evaluating my "--nice" parameters because it's never
> entering that dang loop... :-/
Based on what I see in the case block, the syntax would be
daemon +5 blahd
or whatever. No "--nice". The case match pattern is
[-+][0-9]*)
which matches any number (any length) prefixed with a minus or a plus,
so long as it occurs before the first non-option argument to "daemon".
Again, I'm kinda guessing, and this may not be the behavior actually
*intended* by the script author.
-- Ben
More information about the gnhlug-discuss
mailing list