Subject: Re: Iterating through "fields" in a list
To: None <netbsd-users@netbsd.org>
From: Thomas Kaepernick <Thomas.Kaepernick@web.de>
List: netbsd-users
Date: 02/03/2007 23:13:51
Am Thu, Feb 01, 2007 at 03:30:46AM -0500, schrieb matthew sporleder:
> On 2/1/07, Jan Danielsson <jan.m.danielsson@gmail.com> wrote:
> >Hello all,
> >
> > (Using /bin/sh)
> >
> > I have a set of backup scripts which contain this:
> >
> > tar .... | bzip2 | gpg -r $ENCTO > blarg.tar.bz2.gpg
> >
> > ENCTO is a variable which is set prior to running the scrips. Now I
> >have realized that I need to encrypt to several recipients. I.e.:
> >
> > tar .... | bzip2 | gpg -r foo -r bar > blarg.tar.bz2.gpg
> >
> > Is there some painfully obvious way to construct the string:
> >
> > "-r foo -r bar"
> >
> > from the environment variable:
> >
> > ENCTO=foo bar
> >
> > (Using space as separator)
> >
> > "for" obviously uses file names, and doesn't seem to be able to use
> >space separated lists for processing.
> >
> > (Don't even suggest that I should create two files named "foo" and
> >"bar" somewhere so that I can use "for". Even I realize how ugly *that*
> >is. ;-)
>
>
> Easy but slow:
> FOO="foo bar"
> echo $FOO | awk '{ print "-r " $1 " -r " $2 }'
> -r foo -r bar
>
> Possibly faster:
> for x in `echo $FOO`
> do echo -n "-r $x "
> done
A other way:
-r ${FOO%\ *} -r ${FOO#*\ }
>
> And, obviously, you can do whatever you need to do with the output.
Bye Thomas