bug-bash
[Top][All Lists]
Advanced

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

Re: add a way to declare global variables


From: Bernd Eggink
Subject: Re: add a way to declare global variables
Date: Sat, 12 Dec 2009 18:07:44 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.4pre) Gecko/20090915 Thunderbird/3.0b4

Am 12.12.2009 15:25, schrieb DennisW:
On Dec 12, 4:24 am, Bernd Eggink<address@hidden>  wrote:
Am 12.12.2009 02:11, schrieb Matthew Woehlke:

konsolebox wrote:
I hope the development team will also consider adding a way in bash to
declare global variables inside a function perhaps either with an
option in typeset or declare like -g (same as zsh) and/or a builtin
function like global as similar to local.

I thought variables in functions were /always/ global unless declared
local?

It's the other way round. Regarding typeset and declare, the man page
says: " When used in a function, makes  each name local, as with the
local command. " So within a function, typeset, declare, and local are
synonyms. Using 'local' outside a function is an error, so IMHO this
command is completely redundant. It _would_ make some sense, however, if
its counterpart 'global' existed, as it could help clarify the intended
usage of the variable.

Bernd

--
Bernd Egginkhttp://sudrala.de

$ vars () { var1=123; local var2=456; }
$ vars
$ echo "var1=$var1 "var2=$var2"
var1=123 var2=

How is that "the other way around"?

(Sorry, something went wrong with the last reply)

What I meant is that variables _declared_ in functions are always global.


--
Bernd Eggink
http://sudrala.de




reply via email to

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