Ken Teague wrote:
On Thu, Feb 4, 2010 at 2:09 PM, Dotan Cohen <dotanco...@gmail.com> 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?

You probably want to put the data into an array rather than a
variable.  An explanation of how to do so can be found here:
 http://tldp.org/LDP/abs/html/arrays.html

Scroll down to the end of Example 26-7 (just about Example 26-8).
Basically, direct stdout to a file, then cat the file to add it to an
array.

<snip>
The array=( element1 element2 ... elementN )  initialization
operation, with the help of command substitution, makes it possible to
load the contents of a text file into an array.

#!/bin/bash

filename=sample_file

#            cat sample_file
#
#            1 a b c
#            2 d e fg


declare -a array1

array1=( `cat "$filename"`)                #  Loads contents
#         List file to stdout              #+ of $filename into array1.
#
#  array1=( `cat "$filename" | tr '\n' ' '`)
#                            change linefeeds in file to spaces.
#  Not necessary because Bash does word splitting,
#+ changing linefeeds to spaces.

echo ${arra...@]}            # List the array.
#                              1 a b c 2 d e fg
#
#  Each whitespace-separated "word" in the file
#+ has been assigned to an element of the array.

element_count=${#array1[*]}
echo $element_count          # 8
<snip>


Why not simply use the  t option for content listing :

tar tvf  * --exclude-from $EXCLUDES

Bruno



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to