Re: create variables in a loop?

Liste des GroupesRevenir à cu shell 
Sujet : Re: create variables in a loop?
De : nospam (at) *nospam* lisse.NA (Eberhard W Lisse)
Groupes : comp.unix.shell
Date : 29. May 2024, 18:45:28
Autres entêtes
Message-ID : <lbp7tpF24jbU1@mid.individual.net>
References : 1 2
User-Agent : Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:115.0) Gecko/20100101 Betterbird/115.11.0
On 29/05/2024 18:25, Janis Papanagnou wrote:
On 29.05.2024 12:57, Dr Eberhard W Lisse wrote:
[...]
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)?
 
You've already got the technical answer to your (literal) question.
Basically something like
 
    for currency in USD GBP EUR
    do
        eval "${currency}='some value $((++n))'"
    done
    printf "%s\n" "$USD" "$GBP" "$EUR"
[...]

Thanks to all having answered.

greetings, el

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