0

I need to run a code in order and use some dates in it.

this is what i tried.

t091="2019-04-01"
t092="2019-04-02"
t093="2019-04-03"
t094="2019-04-04"
t095="2019-04-05"
t096="2019-04-06"
t097="2019-04-07"
t098="2019-04-08"
t099="2019-04-09"

for k in {091..099}; do
echo $t${k}
done

and the output:

091
092
093
094
095
096
097
098
099

I can't run the code without using the dates in order. how can I do it?

  • 1
    Why not make `t` into an associative array? – Ted Lyngmo Jan 04 '23 at 07:15
  • how i can do that? – mercuryhuffle Jan 04 '23 at 07:29
  • I was about press "submit" on my answer when the question got closed :-) First `declare -A t=([92]="2019-04-02" [93]="2019-04-03" [91]="2019-04-01" [96]="2019-04-06" [97]="2019-04-07" [94]="2019-04-04" [95]="2019-04-05" [98]="2019-04-08" [99]="2019-04-09" )` then you access the elements with `for k in {91..99}; do` `echo ${t[$k]}` `done` – Ted Lyngmo Jan 04 '23 at 07:31
  • I missed `[91]="2019-04-01"` in the array initialization, but I hope you got the picture. – Ted Lyngmo Jan 04 '23 at 11:21

0 Answers0