bug-bash
[Top][All Lists]
Advanced

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

bash/set - fix for bad expansion of function while used as input


From: Stanislav Brabec
Subject: bash/set - fix for bad expansion of function while used as input
Date: Thu, 1 Feb 2001 21:55:52 +0100
User-agent: Mutt/1.3.13i

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnuname output: Linux 
utx 2.4.0-test10 #29 Čt pro 7 11:03:49 CET 2000 i686 unknown
Machine Type: i686-pc-linux-gnu

Bash Version: 2.04
Patch Level: 0
Release Status: release
                                    
Description:
       set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
              Without options, the name and value of each shell variable
              are displayed in a format that  can be  reused  as input.
                                    
This is resent of mail from Dec 20, 2000, but now it contains fix.
I didn't obtained any reply, so I am sending it again.

Included small script demonstrates it's not true.

Repeat-By:
--------------
#! /bin/bash

function bad_func()
{
  echo `echo This should not be printed!`
}

set >bad_func_dump

. bad_func_dump 2>/dev/null
--------------

Fix:

Included fix removes `=' character from `set' output of functions:

Before patch:
fnc=()
{
foo
}

After patch:
fnc()
{
foo
}
--------------
--- bash-2.04/variables.c.orig  Tue Mar 14 17:36:18 2000
+++ bash-2.04/variables.c       Sat Dec 23 01:42:07 2000
@@ -793,7 +793,7 @@
 {
   if (function_p (var) && var->value)
     {
-      printf ("%s=", var->name);
+      printf ("%s", var->name);
       print_var_function (var);
       printf ("\n");
     }
--------------

There is another alternative:

+      printf ("function %s", var->name);


Notes: I am adding reply of Chet Ramey and my old reply.


On Thu, Dec 21, 2000 at 12:17:54PM -0500, Chet Ramey wrote:
> > Bash Version: 2.04
> > Patch Level: 0
> > Release Status: release
> >                                    =20
> > Description:
> >        set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
> >               Without options, the name and value of each shell variable
> >               are displayed in a format that  can be  reused  as input.
> 
> What solution do users prefer?  POSIX.2 says only variables should be
> printed, but printing functions seems like a reasonable thing to do.
> How about printing only variables in POSIX mode, and printing functions
> (but not as pseudo-assignment statements) when not in POSIX mode?
> 

I like functionallity "as is", but I have complained about unusability
of output of functions. I am adding small patch, which solves my problem
- if var is a function, it will not be dumped as

fnc=()
{
foo
}

but in format

fnc()
{
foo
}

which is reusable. But I don't know, if there's some standard, which
can be broken by my patch. With this patch following script gives
intuitivelly expected empty output.

-- 
Stanislav Brabec



reply via email to

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