Re: create variables in a loop?

Liste des GroupesRevenir à cu shell 
Sujet : Re: create variables in a loop?
De : nn.throttle (at) *nospam* xoxy.net (Helmut Waitzmann)
Groupes : comp.unix.shell
Date : 29. May 2024, 13:36:38
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <83ed9k94mh.fsf@helmutwaitzmann.news.arcor.de>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
 Dr Eberhard W Lisse <nospam@lisse.NA>:
Hi, >
>
I would like to do something like >
>
for i in USD GBP
do
$i=somevalue
done
>
does not work, of course. >
>
Any idea on how to create (and fill variables through a loop)? >
 Yes.
   for i in USD GBP
   do
     somevalue=... &&
     eval "$i"'="$somevalue"'
   done
 But note, that variable names consisting of only upper case  letters, digits, and underscores are by convention reserved for  the environment.  Therefore I recommend to do    for i in USD GBP
   do
     somevalue=... &&
     eval 'currency_'"$i"'="$somevalue"'
   done
 instead, to get variables like currency_USD, currency_GBP, and so  on.
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