[pacman-dev] type -p tests in makepkg
Isaac Good
pacman at isaac.otherinbox.com
Mon Nov 16 19:52:39 EST 2009
On Mon, Nov 16, 2009 at 10:30:07AM +0000, Allan McRae wrote:
> 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
>
While hacks are ugly, I guess there is nothing wrong with that. I'll submit a bug report and maybe this will all be moot...
Just to throw it out, what about this?
type -t package | grep -q 'function' && echo "yes" || echo "no"
More information about the pacman-dev
mailing list