I was trying to insert a nested variable as a while loop condition but I can't manage to expand it properly.
print_message() {
timer=0
timer_condition="$2"
while [[ $timer_condition ]]; do
sleep 1
timer=$((timer+1))
done
echo "$1"
}
print_message 'Hello world, 5 seconds passed...' '$timer != "5"'
print_message 'Hello again, another 10 seconds passed...' '$timer != "10"'
As an example, I created a simple function print_message that accepts 2 arguments: $1 being the message to print and $2 being the condition I want the while loop to test, so that the function could be fed different conditions to display the messages. However, the while loop is testing if $timer_condition itself is true, instead of testing its content. Is there a way to make it work like this?
while [[ $timer != "5" ]]; do
Thank you