From owner-freebsd-stable@FreeBSD.ORG Fri Jun 15 20:09:49 2012 Return-Path: Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CF23D1065675 for ; Fri, 15 Jun 2012 20:09:49 +0000 (UTC) (envelope-from wblock@wonkity.com) Received: from wonkity.com (wonkity.com [67.158.26.137]) by mx1.freebsd.org (Postfix) with ESMTP id 724318FC08 for ; Fri, 15 Jun 2012 20:09:49 +0000 (UTC) Received: from wonkity.com (localhost [127.0.0.1]) by wonkity.com (8.14.5/8.14.5) with ESMTP id q5FK9mTQ028182; Fri, 15 Jun 2012 14:09:48 -0600 (MDT) (envelope-from wblock@wonkity.com) Received: from localhost (wblock@localhost) by wonkity.com (8.14.5/8.14.5/Submit) with ESMTP id q5FK9mb3028179; Fri, 15 Jun 2012 14:09:48 -0600 (MDT) (envelope-from wblock@wonkity.com) Date: Fri, 15 Jun 2012 14:09:48 -0600 (MDT) From: Warren Block To: Oliver Fromme In-Reply-To: <201206151823.q5FINRFT084093@lurza.secnetix.de> Message-ID: References: <201206151823.q5FINRFT084093@lurza.secnetix.de> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.7 (wonkity.com [127.0.0.1]); Fri, 15 Jun 2012 14:09:48 -0600 (MDT) Cc: freebsd-stable@FreeBSD.ORG Subject: Re: devd problem with 9-stable X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jun 2012 20:09:49 -0000 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?