Re: create variables in a loop?

Liste des GroupesRevenir à cu shell 
Sujet : Re: create variables in a loop?
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shell
Date : 29. May 2024, 14:09:31
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <v375tr$1iinj$1@news.xmission.com>
References : 1
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <lbog03FfbrqU1@mid.individual.net>,
Dr Eberhard W Lisse  <nospam@lisse.NA> wrote:
Hi,
>
I would like to do something like
>
for i in USD GBP
do
$i=somevalue
done
>
does not work, of course.

The general answer is to use "eval", so something like:

for i in USD GBP
do
eval $i=somevalue
done

But this doesn't scale well if "somevalue" is other than a simple string.
(But see below...)

Alternatively, with bash, you can use the "nameref" capability - see the
man page for details.

Update to add: this actually works:

    for i in one two three;do eval $i='"$(fortune)"';done

--
"Every time Mitt opens his mouth, a swing state gets its wings."

(Should be on a bumper sticker)

Date Sujet#  Auteur
29 May 24 * create variables in a loop?12Dr Eberhard W Lisse
29 May 24 +- Re: create variables in a loop?1David W. Hodgins
29 May 24 +* Re: create variables in a loop?2Kenny McCormack
29 May 24 i`- How to use "eval" (was: create variables in a loop?)1Helmut Waitzmann
29 May 24 +- Re: create variables in a loop?1Lew Pitcher
29 May 24 +- Re: create variables in a loop?1Helmut Waitzmann
29 May 24 +- Re: create variables in a loop?1Chris Elvidge
29 May 24 +* Re: create variables in a loop?3Janis Papanagnou
29 May 24 i`* Re: create variables in a loop?2Eberhard W Lisse
29 May 24 i `- Re: create variables in a loop?1Kenny McCormack
30 May 24 +- Re: create variables in a loop?1Lawrence D'Oliveiro
30 May 24 `- Re: create variables in a loop?1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal