0

I am writing a shell script, where I am trying to expand one variable in for loop. I google for that but did not find any solution. However this question is very similar to my question but not getting the solution.

expanding variables in shell script

Please check this

time_stamp_1=$(date --date="1min ago" +"%a %b %e %H:%M")
time_stamp_2=$(date --date="2min ago" +"%a %b %e %H:%M")
time_stamp_3=$(date --date="3min ago" +"%a %b %e %H:%M")
time_stamp_4=$(date --date="4min ago" +"%a %b %e %H:%M")
time_stamp_5=$(date --date="5min ago" +"%a %b %e %H:%M")
time_stamp_6=$(date --date="6min ago" +"%a %b %e %H:%M")
time_stamp_7=$(date --date="7min ago" +"%a %b %e %H:%M")
time_stamp_8=$(date --date="8min ago" +"%a %b %e %H:%M")
time_stamp_9=$(date --date="9min ago" +"%a %b %e %H:%M")
time_stamp_10=$(date --date="10min ago" +"%a %b %e %H:%M")
time_stamp_11=$(date --date="11min ago" +"%a %b %e %H:%M")
time_stamp_12=$(date --date="12min ago" +"%a %b %e %H:%M")
time_stamp_13=$(date --date="13min ago" +"%a %b %e %H:%M")
time_stamp_14=$(date --date="14min ago" +"%a %b %e %H:%M")
time_stamp_15=$(date --date="15min ago" +"%a %b %e %H:%M")

for i in {1..15}
do
    req=`$time_stamp_${i}`
    echo "req = $req"
done

How can I print time_stamp 1 to 15 values???

2 Answers 2

0
for i in {1..15}
do
  set time_stamp_$i
  echo req = ${!1}
done
Sign up to request clarification or add additional context in comments.

Comments

0
for i in {1..15}
do
    req=$(echo \$time_stamp_$i)
    eval echo "req = $req"
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.