I am not a good bash scripter yet.
In the following example script, I am trying to move through steps, check the amount of time elapsed since the step started, and use the correct singular or plural ending to describe the amount of time that has passed.
If the amount of time that passes rounds off to 1 second, I would like the script to tell me it took 1 "second" to move through the step and if it is anything else besides 1 second, I would like it to tell me it took x amount of "seconds"
#!\bin\bash
STEP=0
STEPS=4
RUN=1
while [ $RUN -eq 1 ]
do
if (( RUNTIME == 1 ))
then
SEC="second"
else
SEC="seconds"
fi
STEP=$(( STEP + 1 ))
printf "\\nStep $STEP/$STEPS\\n"
printf "Hi!\\n"
TIME=$SECONDS
RUNTIME=$(( TIME - START_TIME ))
printf "That took $RUNTIME $SEC\\n\\n"
STEP=$(( STEP + 1 ))
printf "Step $STEP/$STEPS\\n"
printf "Hi!\\n"
sleep 1s
TIME1=$SECONDS
RUNTIME=$(( TIME1 - TIME ))
printf "That took $RUNTIME $SEC\\n\\n"
STEP=$(( STEP + 1 ))
printf "Step $STEP/$STEPS\\n"
printf "Hi!\\n"
sleep 2s
TIME2=$SECONDS
RUNTIME=$(( TIME2 - TIME1 ))
printf "That took $RUNTIME $SEC\\n\\n"
STEP=$(( STEP + 1 ))
printf "Step $STEP/$STEPS\\n"
printf "Hi!\\n"
sleep 3s
TIME3=$SECONDS
RUNTIME=$(( TIME3 - TIME2 ))
printf "That took $RUNTIME $SEC\\n\\n"
END_TIME=$SECONDS
RUNTIME=$(( END_TIME - START_TIME ))
printf "The script took $RUNTIME $SEC to complete.\\n\\n"
RUN=0
done