Created
July 8, 2017 21:13
-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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