While loop animation

This is just for fun but i can't work it out

I want to animate this dotted line in a shell script.

..................................................................................

I want it to start at one dot like this

.

and end up printing them all.

I think I need a while loop but when I do it, it does this.

.
..
...
....

Any help please

Cheers
Dan

Please post your sample code and mention what Operating System and version you have and what Shell you are using.
Your problem is that you need to append a dot to the dot string with no line-feed. The syntax to do this varies somewhat according to your local environment.

In ksh or bash, something like this what you are wanting?

for (( i = 0; i < 30; i++ ))
do
    printf "."
    sleep 1
done
printf "\n"

The printf, without the \n, does not write a newline, so the next dot is placed on the same line as the previous. One final newline to make it nice when the script exits.

#!/bin/bash

i=1
while (( $i < 10 )); do
	echo .
	let i++
done

Change your echo . to printf "." and then add a final printf with a newline (\n) after the while and you should be in business.

1 Like

Amazing cheers mate