BASH:我如何像 watch 命令一样输出

标签 bash watch

我的 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

关于BASH:我如何像 watch 命令一样输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25332975/

相关文章:

visual-studio - 调试中的 Watch 搜索能力?

javascript - Angular $watch 仅通过 onclick 触发一次

Bash、串行 I/O 和 Arduino

linux - 使用 readline 的多平台(Windows、MacOSX、Linux)应用程序出现问题

linux - 迭代等于文件名 bash

angularjs - 更改变量后的 Angular $watch 函数

linux - 使用 "watch"在 Bash 中重复运行一个函数?

bash - 带有输入文件和输出文档的 Wget

linux - ssh 注销后后台 shell 脚本无法访问目录,即使使用 nohup

angularjs - 如何监视使用 ng-bind-html 创建的 ng-model