我构建了我的网络服务器,我正在尝试进行测试。所以我用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
最佳答案
还有另一种选择,在写入标准输出之前定位光标。
您可以根据需要设置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/