bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about redirecting output of spawned processes


From: Bob Proulx
Subject: Re: Question about redirecting output of spawned processes
Date: Fri, 13 Feb 2009 00:46:19 -0600
User-agent: Mutt/1.5.18 (2008-05-17)

Eric415 wrote:
> separate file specified along with the command. For some reason, when I run
> the master script using nohup [...] each of the commands redirects their
> output to nohup.out instead of the specified file. Any ideas?

The nohup command redirects output to the nohup.out file if the output
is a terminal.  Because it redirected to nohup.out we know that the
output was a terminal at that point and that your attempt at
redirection had failed.

> nohup nice prog1 &> prog1.out
> ${commands[ran]} &

Why has your redirection failed?  Because redirections are processed
before variable expansion.  Because your redirection is included in
the variable which is expanded the redirection is too late.  That is
why it wasn't working.

This can be demonstrated with:

  $ x='>/tmp/out'
  $ echo hello $x
  hello >/tmp/out

Solution?  One way is to add an eval.

  $ eval echo hello $x

And similarly for your case:

  eval ${commands[ran]} &

This will process redirections, expand variables, then run the eval
which will do it all again and on the second pass handle the newly
appearing redirections that results from the previous variable
expansion.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]