FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 11-16-2009, 09:30 AM
Allan McRae
 
Default type -p tests in makepkg

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
 
Old 11-16-2009, 11:52 PM
Isaac Good
 
Default type -p tests in makepkg

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"
 

Thread Tools




All times are GMT. The time now is 05:25 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org