文本刷新不换行

 

C#控制台

            for (int i = 0; i <= 100; i++)
            {
                Console.Write("\r当前进度{0}%", i);
                System.Threading.Thread.Sleep(1000);
            }

Linux

新建一个 Unix 编码 .sh 脚本

vi  time.sh

输入以下内容

#!/bin/bash

while [ 1 ]
do
    a=$(date +"%Y-%m-%d %H:%M:%S")
    echo -ne "$a\r"  #不换行刷新数据
    sleep 2.5; #睡眠2.5秒
done

添加权限并运行脚本

chmod +x time.sh
bash time.sh

 

posted @ 2022-01-17 16:03  雨水的命运  阅读(45)  评论(0编辑  收藏  举报