Article View: es.comp.os.linux.programacion
Article #7950Re: Duda con variables en Shell
From: J.A. Gutierrez
Date: Wed, 22 Jan 2003 11:40
Date: Wed, 22 Jan 2003 11:40
57 lines
2579 bytes
2579 bytes
"Jes�s Mart�nez Mateo" <jmartinez@isdn-si.com> wrote:
: �Como puedo hacer para que la salida de este shell-scripts sea "2"?
#!/bin/ash
echo 2
# :-)
: #!/bin/ash
es encomiable el usar "ash" para asegurarte de que el script
funcionara con un sh standard (pre-POSIX); pero en la version
final deberias dejar "#!/bin/sh" ya que "ash" es algo mas bien
de linux
: PIPO=1
: func() {
: PIPO=2
: export PIPO
: }
man sh:
Functions execute in the same process as the caller and share all files
and present working directory with the caller.
[...]
completes in the environment of the caller. Ordinarily, variables are
shared between the calling program and the function.
Asi que, segun eso, parece que el script deberia funcionar como
tu quieres. Y, efectivamente, si en lugar de llamar a la fucncion
con "foo &" la llamas con "foo" veras que es asi.
Lo que ocurre es que al poner "foo &" se crea un sub-shell
hijo, y como es logico, un proceso hijo no puede cambiar el
entorno de su padre
Tendras que buscar otra forma de hacer lo que quieres...
: echo hola mundo
: func &
: sleep 3
mejor si en lugar de ese sleep pones un wait
--
PGP and other useless info at \
http://www.cps.unizar.es/~spd/ \
finger://daphne.cps.unizar.es/spd \ Timeo Danaos et dona ferentes
ftp://ivo.cps.unizar.es/pub/ \ (Virgilio)
Technical Details
Message-ID:
<b0m00a$d8m$1@news.unizar.es>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!news-zh.switch.ch!irazu.switch.ch!heraldo.rediris.es!lectores.rediris.es!news.rediris.es!news.unizar.es!not-for-mailReferences:
<b0kot2$6ru$1@nsnmrro2-gest.nuria.telefonica-data.net>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,e65f3a603270ff14
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-01-22 03:05:14 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!news-zh.switch.ch!irazu.switch.ch!heraldo.rediris.es!lectores.rediris.es!news.rediris.es!news.unizar.es!not-for-mail
From: "J.A. Gutierrez" <spd@daphne.cps.unizar.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Duda con variables en Shell
Date: 22 Jan 2003 11:40:58 GMT
Organization: Rank
Lines: 57
Message-ID: <b0m00a$d8m$1@news.unizar.es>
References: <b0kot2$6ru$1@nsnmrro2-gest.nuria.telefonica-data.net>
NNTP-Posting-Host: daphne.cps.unizar.es
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: news.unizar.es 1043235658 13590 155.210.152.20 (22 Jan 2003 11:40:58 GMT)
X-Complaints-To: usenet@news.unizar.es
NNTP-Posting-Date: 22 Jan 2003 11:40:58 GMT
User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (IRIX/6.2 (IP22))