[kwlug-disc] Capturing output in scripts

William Park opengeometry at yahoo.ca
Thu Aug 21 15:27:52 EDT 2014


On Thu, Aug 21, 2014 at 03:02:19PM -0400, Khalid Baheyeldin wrote:
> On Thu, Aug 21, 2014 at 2:59 PM, William Park <opengeometry at yahoo.ca> wrote:
> 
> > 1. Upgrade Vim
> 
> To what version? I have 7.4, which is what ships with Kubuntu 14.04.

I have 7.4.50 (with Slackware 14.1), and syntax colours look okay with
().

> > 2. Use 'exec' builtin.
> 
> Can you expand a bit on what you mean?

The following

    exec 3<&1 4>&2  2>&1 1>/tmp/logfile
    ...
    exec 1<&3- 2<&4-

will do the same thing as far as redirections go.  First exec saves
fd=1/2 to fd=3/4, and do the redirections.  Second exec restores fd=1/2
from fd=3/4, and closes fd=3/4.

Catch is, commands in between will be executed in the current shell.
This may or may not be what you had in mind when the script was written.
For example, in subshell, variables don't move up to parent shell.  With
'exec', you're changing variables at the parent shell level.  Other than
that, it should be the same thing.
-- 
William





More information about the kwlug-disc mailing list