简体   繁体   English

BASH:如何在watch命令中进行输出

[英]BASH:How do i make output like in watch command

My linux 'watch' command is quite old and doesn't support '--color' option. 我的linux'watch'命令很旧,并且不支持'--color'选项。 How can I have same output like it does? 如何获得与之相同的输出? because in my script the loop gives output one after another(of course). 因为在我的脚本中,循环会一个接一个地输出(当然)。 But i need it to replace the previous. 但是我需要它来代替以前的。 Is there any tricks with terminal output? 终端输出有什么技巧吗?

#!/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

You can use clear to clear the screen before dumping your output to give the appearance of in-place updates. 在转储输出以显示就地更新之前,可以使用clear清除屏幕。

To reduce blinking, you can use the age old technique of double buffering: 要减少闪烁,可以使用双重缓冲的古老技术:

#!/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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM