Venus200
Venus200

Reputation: 1

Create a graph with for loop Linux

We got 3 variables,a=5; b=7; c=9. Those numbers are changing the whole time. I want to make a graph with asterisks bye using a for loop. Example output:

a = *****

b = *******

c= *********

But when those numbers change then the graph must also change. Something like an update.

Can someone help me with this?

Upvotes: 0

Views: 42

Answers (1)

choroba
choroba

Reputation: 241988

This could help you. It uses the special ANSI code to move the cursos 3 lines up.

#!/bin/bash

stars () {
    local header=$1
    local count=$2
    printf '%s ' "$header"
    for i in $(seq $count) ; do
        printf '*'
    done
    printf ' \n'  # Space needed to remove the last star when shortening.
}

a=5
b=7
c=9

while : ; do
    stars a $a
    stars b $b
    stars c $c
    printf $'\033[3A'  # Go 3 lines up
    (( a+=RANDOM%3-1 ))
    (( b+=RANDOM%3-1 ))
    (( c+=RANDOM%3-1 ))
    sleep .1
done

Upvotes: 1

Related Questions