我建立了我的网络服务器,我想做一个测试。所以我用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
因此,我为echo
添加了-ne
,但它似乎没有按预期工作。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
型
4条答案
按热度按时间bfrts1fy1#
还有另一个选项,在写入stdout之前定位光标。
您可以根据需要设置
x
和y
。字符串
hiz5n14c2#
您可以在while循环的开头添加
clear
命令。这将使echo语句在每次迭代期间保持在屏幕顶部,如果这就是您所想的。ryoqjall3#
当我做这类事情时,我不使用curses/ncurses或
tput
,而是将自己限制在一行中,并希望它不会换行。我在每次迭代中都重新画线。举例来说:
字符串
如果您没有显示可预测长度的文本,则可能需要首先重置显示(因为它不会清除内容,所以如果您从
there
转到here
,则最终将显示heree
,其中包含前一个字符串中的额外字母)。要解决这个问题:型
这将放置一个全宽的空格行来清除以前的文本,然后用新内容覆盖现在空白的行。我已经使用了检索到的文件的第一行的一段,最大为该行的宽度(计算额外的文本;我可能在某个地方离开)。如果我可以只使用
head -c$((COLUMNS-28)) -n1
(这会关心顺序!).0mkxixxg4#
请在下面尝试。
字符串