[pacman-dev] type -p tests in makepkg

Allan McRae allan at archlinux.org
Mon Nov 16 05:30:07 EST 2009


Hi,

I would like some clarification on what the bug in bash is that prevents 
us using [[ style tests when testing if a function exists.  We have this 
in the two patches that change all the tests in makepkg:

* if [ $(type ... preserved due to a bash bug with [[ and set -e and ERR 
traps

I also have a patch from Cedric that makes the build() function optional 
which uses [[ for the "type -p" test.

Here is an example script based on code Cedric provided:

--start--
#!/bin/bash -e

set -E
trap 'echo >&2 "DANGER: ERRORS ABOUND!"' ERR

build() {
  echo "build"
}

[[ $(! type -t build) = "function" ]] && echo "yes" || echo "no"
[[ $(! type -t package) = "function" ]] && echo "yes" || echo "no"
--end--

That outputs "yes" for the build function and "no" for the package 
function without an error trap being triggered. I know the "!" is a 
workaround to stop the error trap being triggered, but is there 
something wrong with that?

Allan



More information about the pacman-dev mailing list