On Fri, 15 Jun 2012, Oliver Fromme wrote:
> When the event is seen:
> Executing 'devnum=`echo ugen0.6 | sed -e 's/^ugen//'` && echo devnum: > /tmp/example
&& echo cdev: ugen0.6 >> /tmp/example'
>
> $devnum never gets a value, the contents of /tmp/example are:
> devnum:
> cdev: ugen0.6
>
> Trying $() instead of backticks makes it worse:
> Executing 'devnum=$(echo $cdev | sed -e 's/^ugen//') && echo devnum: $devnum > /tmp/example
&& echo cdev: $cdev >> /tmp/example'
Unfortunately, the manual page does not explain how the action
strings are parsed exactly. I guess the problem is not the
backticks but the fact that the parser tries to expand $devnum
as a devd variable, so the shell never sees it. This also
explains why using $() makes things worse.
It should be pointed out that this is a regression from 8.x.
You can try to prepend a backslash, i.e. echo \$devnum. This
isn't documented, but then again, using backslashes to continue
strings that span multiple lines isn't documented either.
devd has already expanded variables by then:
Executing 'devnum=ugen0.6 && echo devnum: \ > /tmp/example && echo cdev: ugen0.6
>> /tmp/example'
It does seem to work to use the bracketed form:
action "devnum=`echo $cdev | sed -e 's/^ugen//'` && echo ${devnum} >
/tmp/example";
In case the sed command still doesn't work, alternatively you
can use shell substring processing instead (this is also more
efficient because the shell doesn't have to create a pipe and
fork a sed process):
action "devnum=$cdev; devnum=\${devnum##ugen}; echo \$devnum > /tmp/foo"
Or even:
action "devnum=$cdev; echo \${devnum##ugen} > /tmp/foo"
I like that, and it does work without the backslash.
action "devnum=$cdev ; echo ${devnum##ugen} > /tmp/example";
cat /tmp/example
0.6
I started to enter a PR, but got confused partway through. The problem
here is that devd is expanding variables unknown to it in action strings
(unless the bracket notation is used), and replacing them with empty
strings. Agreed?
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "[email protected]"