Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to control cursor position.(Ex.1)
#!/bin/bash
# 1. 指定文字数左へ移動後に echo
# ( 最後の echo 以外は改行しない )
#
echo -n `date +"%Y-%m-%d %H:%M:%S"`
for i in {0..4};
do
sleep 1
tput cub 19
echo -n `date +"%Y-%m-%d %H:%M:%S"`
done;
tput cub 19
echo `date +"%Y-%m-%d %H:%M:%S"`
echo "-------------------"
# 2. 指定行数上へ移動後に echo
# ( 毎回改行 )
#
echo `date +"%Y-%m-%d %H:%M:%S"`
for i in {0..4};
do
sleep 1
tput cuu 1
echo `date +"%Y-%m-%d %H:%M:%S"`
done;
tput cuu 1
echo `date +"%Y-%m-%d %H:%M:%S"`
echo "-------------------"
# 3. 行の先頭へ復帰(CR(\r))後 printf
# ( 最後の echo 以外は改行しない )
#
printf "%10s %8s" `date +"%Y-%m-%d %H:%M:%S"`
for i in {0..4};
do
sleep 1
printf "\r%10s %8s" `date +"%Y-%m-%d %H:%M:%S"`
done;
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment