Bash script that shows changing real time values from commands

You can use tput cup 0 0 to send the cursor up to the top left of the screen. clear once.

#!/bin/bash
clear
while sleep 1; do
    tput cup 0 0
    printf "%21s %6d    \n" \
      "Célula calibrada: "   $(npe ?AI1) \
      "Anemómetro: "         $(npe ?AI2) \
      "Célula temperatura: " $(npe ?AI3) \
      "Célula temperatura: " $(npe ?AI4)
done

It might be tricky to implement a real time solution in bash.

There are many ways to run script once in X seconds you can use watch. I assume you already have myScript.sh available. Replace X with number of seconds you need.

  1. watch -n X ./myScript.sh

  2. while sleep X; do ./myScript.sh; done

    upd. to emulate watch you might want to clear the screen in between iterations. inside the script it will look this way:

    while sleep X; do 
       clear; 
       command1;
       command2;
    done
    
  3. add one of options above to the script itself.


I am assuming the flicker is because your commands take a moment to return their values. This is my usual workaround:

cmds(){
  echo "Célula calibrada: " $(npe ?AI1);
  echo "Anemómetro: " $(npe ?AI2);
  echo "Célula temperatura: " $(npe ?AI3);
  echo "Célula temperatura: " $(npe ?AI4);
}

while true; do
  out="$(cmds)"
  clear
  echo "$out"
  sleep 1
done

The idea being that we clear the screen at the last possible moment.