aelor
aelor

Reputation: 11116

loop and print stars in same line unix command

Hi I have written a script which has a while loop in it. The script when ran takes time to complete so I planned to add something to show as a loading bar.

Now I have added stars like this:

while read line
do
         #MY SCRIPT IS HERE

        echo "*"
done < finalout.txt

Now my problem is when I am printing the stars, one star star gets printed per line. like this

*
*
*
*

How is it possible to show it printing in increasing order so that it looks like a loading bar.

***** and increasing with the while loop

Upvotes: 1

Views: 3249

Answers (2)

Gary_W
Gary_W

Reputation: 10360

Instead of

echo "*"

use

echo -e "*\c"

To suppress the newline.

Upvotes: 0

anubhava
anubhava

Reputation: 785631

You can use:

echo -n '*'

OR

printf '*'

inside the while loop to print characters in the same line. Outside you can add echo to get one final newline as:

while read line
do
    echo -n '*'
done < finalout.txt
echo

Upvotes: 4

Related Questions