Re: Executing a command in sub-shell

From: udayan (udayan_singh_at_lko.tcs.co.in)
Date: 02/12/04


Date: 12 Feb 2004 01:16:09 -0800

Kevin Rodgers <ihs_4664@yahoo.com> wrote in message news:<402ACB9B.4030908@yahoo.com>...
> udayan wrote:
> > Kevin Rodgers <ihs_4664@yahoo.com> wrote in message
> news:<40292020.7050703@yahoo.com>...
> > Apart from above mentioned, I am not able to understand the behaviour
> > mentioned below -
> >
> > ###########Code -
> > #!/bin/sh
> >
> > MY_NAME="UDAYAN"
> > cleartool setview usingh_dev_view <<- _setview
> > echo "my view is usingh_dev_view "
> > cleartool pwv
> > cleartool setact Tools <<- _setact
> > val1=0
> > echo "val1 = ${val1}"
> > echo ${MY_NAME}
> > _setact
> > cleartool pwv
> > _setview
> > echo "val1 = ${val1}"
> >
> > #############script ends here . Now the output follows
> > my view is usingh_dev_view
> > Working directory view: ** NONE **
> > Set view: usingh_dev_view
> > Set activity "Tools" in view "usingh_dev_view".
> > Working directory view: ** NONE **
> > Set view: usingh_dev_view
> > val1 =
> >
> >
> > ########### here the value of val1 is not printed ?? why??
>
> It's not clear at all, because there are 2 `echo val1` commands in your
> script and only 1 line of output, and apparently the nested subshells'
> eoutput is interleaved (perhaps because some commands are writing to
> standard output and some to standard error).

Well I'll again give the code with slight modifications - This is
exactly what i m getting -
###########Code starts here -
#!/bin/sh

MY_NAME="UDAYAN"
cleartool setview usingh_dev_view <<- _setview
        echo "my view is usingh_dev_view "
        cleartool pwv
        echo "${MY_NAME}"
        cleartool setact Tools <<- _setact
                echo "hi"
                cleartool pwv
        _setact
_setview
################Code ends here , and now the output
my view is usingh_dev_view
Working directory view: ** NONE **
Set view: usingh_dev_view
UDAYAN
Set activity "Tools" in view "usingh_dev_view".
###################Output ends here.
See the lines -
'echo "hi"'
cleartool pwv
 - in the other second sub-shell. They are never printed out on the
screen!!
This was the thing which i m not able to understand.

>
> In any case, the first reference to ${val1} occurs within the here
> document, which is expanded by the shell where it has not been set.

Nope i dont agree.. If you look on the previous piece of code, there
the val1 is echoed in the same second sub-shell.

> To
> expand it dynamically in the subshell, it needs to be quoted in the here
> document:
>
> echo "val1 = \${val1}"
>
> (And since it's 2 levels deep, it may need to be quoted twice. :-)

Might be if i had done something like this then it would have come up.

>
> The second occurrence occurs in the shell script, after the subshell
> where it was set has exited. Just as a child process can't effect the
> environment of its parent process, a subshell can't set a variable in
> its parent shell, so you're out of luck there.

this brings a new topic.. how can i export my variables to the parent
shell from the sub-shell?

tia,
us



Relevant Pages

  • Re: How can I get the value of a variable from within awk script into shell?
    ... I have to write a bash-shell script to process a file. ... I use in this shell script these awk ... This is more a shell problem than an awk problem. ... in a subshell, and this seems to be your case. ...
    (comp.lang.awk)
  • Re: alias to the sub shell
    ... :>: A script without a shebang is a new process, not a subshell. ... The shell then is allowed to determine how to process it. ...
    (comp.unix.shell)
  • Re: alias to the sub shell
    ... :>: A script without a shebang is a new process, not a subshell. ... The shell then is allowed to determine how to process it. ...
    (comp.unix.shell)
  • Re: alias to the sub shell
    ... the shell I'm using is korn shell ... This is not a subshell, ... A script without a shebang is a new process, ... aliases are superseded by shell ...
    (comp.unix.shell)
  • Re: Executing a command in sub-shell
    ... On Thu, 12 Feb 2004 at 09:16 GMT, udayan wrote: ... subshell to a variable, or have the parent shell eval the output ...
    (comp.unix.shell)

Loading