Skip to content

Instantly share code, notes, and snippets.

@delenamalan
Created July 8, 2017 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delenamalan/e878e27ba6589e25bf14b2108a2220d7 to your computer and use it in GitHub Desktop.
Save delenamalan/e878e27ba6589e25bf14b2108a2220d7 to your computer and use it in GitHub Desktop.
Repeat a bash command from https://stackoverflow.com/a/41191408/3486675 e.g. repeat_command.sh "kubectl get pods --all-namespaces"
#!/bin/bash
while true; do
# COMMAND=$(kubectl get pods --all-namespaces) #Save command result in a var.
COMMAND=$($1) #Save command result in a var.
echo "$COMMAND" #Print command result, including new lines.
sleep 3 #Keep above's output on screen during 3 seconds before clearing it
#Following code clears previously printed lines
LINES=$(echo "$COMMAND" | wc -l) #Calculate number of lines for the output previously printed
for (( i=1; i <= $(($LINES)); i++ ));do #For each line printed as a result of COMMAND"
tput cuu1 #Move cursor up by one line
tput el #Clear the line
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment