[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question in Shell script
- To: http://www.blore.tcs.co.in/~Murugesh_R
- Subject: Re: Question in Shell script
- From: http://dummy.us.eu.org/robert (Robert)
- Date: Tue, 29 Jul 2003 14:27:59 -0400
- In-reply-to: <http://www.tcs.co.in/~OF32766600.7592B600-ON65256D72.001D0CB2>
- Keywords: crm114
> From: http://www.blore.tcs.co.in/~Murugesh_R
> Date: Tue, 29 Jul 2003 10:49:56 +0530
>
> Hi Robert,
> I need a favour from you regarding C-shell scripts.
> I need to set a variable in the shell - environment through my script ,
> not thro' the .cshrc file.
> say for e.g I have two scripts my1 and my2.
>
> Im my1.
> #!/bin/csh
> setenv TEMP TEST
>
> I executed this script after giving the necessary permissions (chmod 755).
>
> Now I want to use this variable in my second script i.e my2, but Im getting
> an error saying undefined variable.
> In the command line I typed echo $TEMP, its says TEMP:undefined variable.
> I would be delighted to hear from you at the earliest.
Unless my1 calls/executes my2, the environment will not contain $TEMP.
For example, say you have the process hierarchy:
/bin/csh
\---- /bin/csh
that is, from a /bin/csh, you create another /bin/sh. If you do
setenv FOO BAR
in the second /bin/csh, and then exit that shell, the $FOO variable will
disappear. On the other hand, if you create another subshell, so you then
have:
/bin/csh
\---- /bin/csh
\---- /bin/csh
and from this /bin/csh, you do "echo $FOO", it will correctly have the
value "BAR".
In other words, environment variables are not like global variables. They
are more like dynamically scoped variables (like "local" variables in
Perl), that is, variables are inherited from their parent process (or, in
the case of Perl, inherited from their parent function).
> Thanks and regards
> Murugesh R