Re: Executing a command in sub-shell
From: Kevin Rodgers (ihs_4664_at_yahoo.com)
Date: 02/12/04
- Next message: Kevin Rodgers: "Re: Executing a command in sub-shell"
- Previous message: Nima Emgushov: "Re: Reading input from 2 files and output to screen after calculation"
- In reply to: udayan: "Re: Executing a command in sub-shell"
- Next in thread: udayan: "Re: Executing a command in sub-shell"
- Reply: udayan: "Re: Executing a command in sub-shell"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 11 Feb 2004 17:40:59 -0700
udayan wrote:
> Kevin Rodgers <ihs_4664@yahoo.com> wrote in message
news:<40292020.7050703@yahoo.com>...
> Now from the code that you told me -
> ...
>>>>cleartool setview view_name <<- _setview
>>>> command_v_1
>>>> ...
>>>> command_v_N
>>>> cleartool setact activity_name <<- _setact
>>>>
> ...
> After this point i should be into the command prompt and not execute
> the code further (till i type exit from the command prompt).
Well, that's tricky. If you don't redirect standard input for the
`cleartool setact activity_name` command, it inherits its input from the
`cleartool setview view_name` command, whose standard input is the here
document terminated by _setview.
Unless you don't have any canned commands that have to run in the
`cleartool setact activity_name` subshell...
> Only when i type exit from the command prompt then i should go into
> the sub-shell created by "cleartool setview view_name".
... Now I understand what you want to do.
Onew way would might be to redirect the second subshell's input from the
terminal, either /dev/tty or `tty` (instead of a here document):
cleartool setact activity_name << /dev/tty
A better way might be like this:
{
echo command_v_1
...
echo command_v_N
cleartool setact activity_name
} |
cleartool setview view_name
> 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).
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. 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. :-)
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.
-- Kevin Rodgers
- Next message: Kevin Rodgers: "Re: Executing a command in sub-shell"
- Previous message: Nima Emgushov: "Re: Reading input from 2 files and output to screen after calculation"
- In reply to: udayan: "Re: Executing a command in sub-shell"
- Next in thread: udayan: "Re: Executing a command in sub-shell"
- Reply: udayan: "Re: Executing a command in sub-shell"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|