我建立了我的网络服务器,我正在尝试做一个测试。所以我用 bash 脚本模拟了很多请求:
i=0
while [ $i -lt 20 ]; do
echo ''
echo ''
echo ''
echo '============== current time ==============='
echo $i
echo '==========================================='
echo ''
curl -i http://www.example.com/index?key=abceefgefwe
i=$((i+1))
done
这很有效,但我更喜欢在终端的同一位置制作所有
echo
。我读过这个:How to show and update echo on same line
所以我为
-ne
添加 echo
但它似乎没有按预期工作。curl
的消息仍然可以将 echo
推开。这就是我需要的:
============== current time =============== ---\
1 <------ this number keeps updating ----> the 3 lines stay here
=========================================== ---/
Here is the messages of `curl`, which are showing as normal way
最佳答案
还有另一种选择,在写入标准输出之前定位光标。
您可以设置 x
和 y
以满足您的需要。
#!/bin/bash
y=10
x=0
i=0
while [ $i -lt 20 ]; do
tput cup $y $x
echo ''
echo ''
echo ''
echo '============== current time ==============='
echo $i
echo '==========================================='
echo ''
curl -i http://www.example.com/index?key=abceefgefwe
i=$((i+1))
done
关于linux - bash:如何在同一位置回显字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44666308/