[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: eval in functions in pipelines doesn't set variables globally

From: Sven Wegener
Subject: Re: eval in functions in pipelines doesn't set variables globally
Date: Mon, 13 Feb 2006 17:45:31 +0100
User-agent: Mutt/1.5.11

On Mon, Feb 13, 2006 at 04:19:42PM +0100, address@hidden wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: sparc
> OS: solaris2.8
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc' 
> -DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8' 
> -DCONF_VENDOR='sun' -DLOCALEDIR='/sw/opensrc/gnu/share/locale' 
> -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  
> -I/sw/opensrc/gnu/include -I/sw/opensrc/include 
> -I/sw/opensrc/include/freetype2 -I/usr/local/ssl/include -O6
> uname output: SunOS suni2 5.8 Generic_117350-24 sun4u sparc 
> SUNW,Sun-Blade-2500
> Machine Type: sparc-sun-solaris2.8
> Bash Version: 3.1
> Patch Level: 0
> Release Status: release
> Description:
>       Normally, the eval builtin used in functions to set variables
>       makes these variables available globally otutside the function.
>       However, when the function gets input from a pipline, the variables
>       are set only locally. This bug was already present in bash-3.0, maybe
>       also in earlier version. The correct behavior would be very usefull
>       to be able to write functions which receive stdin and put it's 
>       contens - preprocessed by awk or similar - into an array. 

If you pipe something, the recipient of the piped data will be executed
in a subshell and can't set variables of the calling shell. This is just
how pipe'ing works. You can do an hackish workaround like:

evalfunc_stdin B test < <( echo )

to execute the function in the current shell and receive input on stdin.

Cheers, Sven

Sven Wegener
Gentoo Developer

Attachment: pgpZlNeAQ7BZ4.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]