我的linux 'watch'命令很旧,不支持'——color'选项。我怎样才能得到和它一样的输出呢?因为在我的脚本中,循环给出了一个接一个的输出(当然)。但我需要它来代替之前的。终端输出有什么技巧吗?
#!/bin/bash
while true
do
/usr/sbin/asterisk -rx "show queue My_Compain"
| grep Agent
| grep -v (Unavailable)
| sort -t"(" -k 2
| GREP_COLOR='01;31' egrep -i --color=always '^.*[0-9] (Not in use.*$|$'
| GREP_COLOR='01;36' egrep -i --color=always '^.*(Busy*$|$'
sleep 2
done
您可以使用clear
在转储输出之前清除屏幕,以提供就地更新的外观。
要减少闪烁,您可以使用古老的双缓冲技术:
#!/bin/bash
while true
do
buffer=$(
clear
/usr/sbin/asterisk -rx "show queue My_Compain"
| grep Agent
| grep -v (Unavailable)
| sort -t"(" -k 2
| GREP_COLOR='01;31' egrep -i --color=always '^.*[0-9] (Not in use.*$|$'
| GREP_COLOR='01;36' egrep -i --color=always '^.*(Busy*$|$'
)
echo "$buffer"
sleep 2
done