Unix questions - Re: How to redirect the output within a sub-shell (& newgrp)

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > November 2005 > Re: How to redirect the output within a sub-shell (& newgrp)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: How to redirect the output within a sub-shell (& newgrp)
Michael Paoli

2005-11-08, 6:29 pm

How about some about some useful hints:
$ cat foo
#!/bin/ksh
id -n -g
[ -f file ] && rm file
$ cat foo
#!/bin/ksh
id -n -g
[ -f file ] && rm file
/usr/bin/newgrp cdrom << \__EOT__
(
echo "I am here"
echo "Bye now"
) > file
__EOT__
ls -g file
[ -f file ] && rm file
$ ./foo
users
-rw------- 1 cdrom 18 Nov 6 16:19 file
$ SHELL=/bin/csh ./foo
users
Too many ('s.
ls: file: No such file or directory
$ 2>>/dev/null fgrep -l "Too many ('s" /bin/*sh* /usr/bin/*sh*
/bin/bsd-csh
/bin/csh
/bin/tcsh
/usr/bin/tcsh
$

Now can you think of the ways the unexpected behavior is likely
creeping in?

venky wrote:
> Thanks Chris for your reply.
>
>
> Yes we do need it. Its not just accessing the files , also executing
> some clear case commands(Clear case is a configuration Management tool
> ), doing builds etc.,
>
>
> Ok let me be clear this time. We have a build script of around 400
> lines of codes of code which contains so many functions, clear case
> commands etc., All these things should be executed in newgrp. I am
> trying to execute a sample script, by which the same logic can be
> used for the build script.
>
> 1) I need to execute the script from 'newgrp' which can be done as
> follows.
> /bin/newgrp nemo <<endnewgr
> set of commands
> endnewgr
>
> 2) I need to redirect the output of each commands, both stdout, stderr
> to a file within newgrp shell. When i try as below,
> /bin/newgrp nemo <<endnewgr
> (
> echo "I am here"
> echo "Bye now"
> ) > out
> endnewgr
>
> I am getting output as :
> ====
> svenkat@sparta /home/svenkat/work > sh b.sh
> + /bin/newgrp nemo
> (
> echo "ok"
> echo "bye now"
> ) > out
> Too many ('s.
> ==========
>
> Otherwords, if
> (
> echo "ok"
> echo "bye now"
> ) > out
>
> works why not the previous code is failing to redirect the output
> within newgrp subshell?
> or what needs to be done to achieve the same.


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com