Re: Bash question: get output as a variable?
On Thu, Feb 4, 2010 at 11:32 PM, Stephen Powell <email@example.com> wrote:
> On Thu, 4 Feb 2010 17:09:28 -0500 (EST), Dotan Cohen wrote:
>> I'm scripting a backup solution, the line that does the business looks
>> like this:
>> tar -zcvf - * --exclude-from $EXCLUDES | openssl des3 -salt -k $1 |
>> dd of=$(hostname)-$(date +%Y%m%d).tbz
>> Because of the "v" flag tar writes to stdout the name of each file
>> copied. How can I get that output redirected to a variable, to use
>> later in the script?
> First of all, let me preface my remarks by saying that I am just
> learning shell scripting myself and definitely consider myself a
> novice. Some guru out there may (and probably does) know a better
> Using a variable is problematic, since a pipeline runs in a subshell
> environment. In fact, each stage of the pipeline is a separate
> process. Thus, any variables set in a pipeline stage do not
> affect the values of the corresponding variable names in the shell
> environment that invoked the pipeline.
> How about something like this?
> tar -zcvf - * --exclude-from $EXCLUDES | tee /tmp/data$$ | \
> openssl ...
In this case output goes to stderr, so:
tar -zcvf - * --exclude-from $EXCLUDES 2> /tmp/data$$ | openssl ...
> . logic to process the /tmp/data$$ data file
> rm /tmp/data$$
> To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact firstname.lastname@example.org