Date: Fri, 15 Jun 2012 14:09:48 -0600 (MDT) From: Warren Block <wblock@wonkity.com> To: Oliver Fromme <olli@lurza.secnetix.de> Cc: freebsd-stable@FreeBSD.ORG Subject: Re: devd problem with 9-stable Message-ID: <alpine.BSF.2.00.1206151250140.27941@wonkity.com> In-Reply-To: <201206151823.q5FINRFT084093@lurza.secnetix.de> References: <201206151823.q5FINRFT084093@lurza.secnetix.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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?
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.00.1206151250140.27941>