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

Cedric Staniewski cedric at gmx.ca
Fri Nov 6 15:01:04 EST 2009


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.


More information about the pacman-dev mailing list