bug-bash
[Top][All Lists]
Advanced

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

Why is this executed inside a subshell?


From: Com MN PG P E B Consultant 3
Subject: Why is this executed inside a subshell?
Date: Mon, 27 Nov 2006 14:28:35 +0100

Consider the following program:

#!/usr/local/bin/bash --norc
export VAR=A
function setvar
{
  VAR=B
  echo X
}
V=$(setvar)
echo $VAR

When I execute it, I get as result "A", not "B", as I had expected.

If setvar would be an external program, I would understand the result,
as this would have to be run in a subshell; but it is a shell function,
and shell functions are supposed to be evaluated in the context of the
current environment. But it seems that within a $(...), even shell 
functions are executed in a child process. Is this supposed to work that

way?

Ronald, using bash 2.05b.
-- 
Ronald Fischer (phone +49-89-63676431)
mailto:mn-pg-p-e-b-consultant-3.com@siemens.com




reply via email to

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