2

I am trying to use the #REPLY input variable in the following for loop code below;

If I use syntax such as for i in {60..0} then it works fine however; trying the input variable from the read statement "for i in {$REPLY..0}" it fails. It appears that the read does not recognize the input as an integer value; can someone assist please?, thank you.

#!/bin/bash
clear
tput cup 5
read -p "What is the number of seconds? "
echo "Started:" $(date)
echo " "
echo " "
echo "Countdown Timer"
echo " "

for i in {$REPLY..0}
do
  tput cup 10 $1
  printf '%dh:%dm:%ds\n' $(($i/3600)) $(($i%3600/60)) $(($i%60))
  tput civis
  sleep 1
done
tput cnorm
echo " "
echo "Finished:" $(date)
1

1 Answer 1

2

Yes, you can't use a variable in brace expansion. So, the solution is simple arithmetic form loop :

for ((i=REPLY; i>=0; i--)); do
    [...]

...and please, no responses with the evil eval, thanks

Sign up to request clarification or add additional context in comments.

1 Comment

That worked, thank you very much for your great assistance.

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.