[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#218530: Suboptimal conditional rune for initscripts



Mark Baker wrote:
> Ian Jackson wrote:
> 
> >Package: debian-policy
> >Version: 3.6.1.0
> >
> >While trying to merge an NMU to my package, I spotted an idiom
> >obviously copied from the policy manual:
> >
> >       if [ -x /usr/sbin/invoke-rc.d ] ; then
> >		invoke-rc.d package <action>
> >       else
> >		/etc/init.d/package <action>
> >	fi
> >
> >This would be better expressed as
> >
> >	if type -p invoke-rc.d >/dev/null 2>&1; then
> >	...
> >
> I think it's debatable whether searching the path for a command in an 
> init script is a good thing, but if we don't search the path for the 
> test we shouldn't do it when we actually execute the command, so the 
> code you quote is wrong either way.

Additionally using 'type -p' is bash specific.  Therefore it should
not be used in /bin/sh scripts.  Instead POSIX standard /bin/sh syntax
such as 'command -v' should be used.  I will rewrite the example for
clarity.

	if command -v invoke-rc.d >/dev/null 2>&1 ; then
		invoke-rc.d package <action>
	...

-- 
Bob Proulx <bob@proulx.com>
http://www.proulx.com/~bob/



Reply to: