bug-bash
[Top][All Lists]
Advanced

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

Re: Issues with exported functions


From: Gabriel Corona
Subject: Re: Issues with exported functions
Date: Thu, 25 Sep 2014 10:52:12 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

Hello,

As the interface is not specified, would it make sense to:

 * add a prefix (use BASH_FUNCTION_foo instead of foo for exported
   function foo);

 * still expand the variable if it matches the 'exported function'
   pattern.

The first point would reduce the probability of a clash with
a user variable:

  foo() {
    echo Executing function "$@"
  }

  foo="aa"
  
  export -f foo
  export foo
  
  bash -c foo
  # OK
  
  bash -c 'echo $foo'
  # OK as well
  
  bash -c env
  # In fact the environment variable is set twice, I didn't know it was event 
possible
  
  dash -c 'echo $foo'
  # Dash find the second one: () { echo Executing function "$@" }

The second (more important) point would allow a variable to begin with
"() {}" or similar:

  $ x="() {}"  bash -c 'echo $x' 2>/dev/null
  
  $ x="() {}"  dash -c 'echo $x' 2>/dev/null
  () {}

--
Gabriel



reply via email to

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