[pacman-dev] [PATCH] scripts: replace test builtin [ with shell keywords [[ and ((

Isaac Good pacman at isaac.otherinbox.com
Sat Nov 7 20:39:38 EST 2009


On Fri, Nov 06, 2009 at 08:01:04PM +0000, Cedric Staniewski wrote:
> Forgot to point out that the 'type -p anything' tests might not work as intended.
> 
> > -		if [ ! "$(type -p xdelta3)" ]; then
> > +		if ! type xdelta3 &>/dev/null; then
> 
> 
> $ type asdf
> bash: type: asdf: not found
> $ type -p asdf; echo $?
> 1
> $
> $
> $ touch ~/bin/asdf; chmod +x ~/bin/asdf
> $ type asdf
> asdf is /home/makepkg/bin/asdf
> $ type -p asdf; echo $?
> /home/makepkg/bin/asdf
> 0
> $ rm ~/bin/asdf
> $
> $
> $ asdf() {
> > echo 1
> > }
> $ type asdf
> asdf is a function
> asdf () 
> { 
>     echo 1
> }
> $ type -p asdf; echo $?
> 0
> 
> 
> That means you cannot rely on the return code when you want to emulate which.
> You have to test the length of the resulting string instead.
> 

If the command is a bash function, is that not good enough? (ie why the -p)
type -pf will suppress functions, so you can do : if type -pf xdelta3 ; then

$  type -p q ; echo $? ; q () { echo ; } ; type -pf q ; echo $? ; type -p q ; echo $?
1
1
0

Definitely worth its own patch, though.

- Isaac


More information about the pacman-dev mailing list