首页 > 解决方案 > 无法重定向所有自制桶过时的输出?

问题描述

我正在编写一个脚本来确定要升级哪些过时的木桶,因为brew cask upgrade不会升级所有带有编号版本的木桶,也不会brew cask upgrade --greedy升级那些带有自动更新的木桶。

但是当我使用brew cask outdated --greedy 2>&1 | grep -v '\(latest\)'自动更新过滤掉木桶时,它就不起作用了。

我的输出brew cask outdated --greedy

google-drive-file-stream (latest) != latest
namechanger (3.4.2) != 3.4.3
quicklook-json (latest) != latest
timemachineeditor (latest) != latest
visual-studio-code (1.39.0) != 1.39.1
webpquicklook (latest) != latest

而输出brew cask outdated --greedy 2>&1 | grep -v '\(latest\)'

google-drive-file-stream
namechanger
quicklook-json
timemachineeditor
visual-studio-code
webpquicklook

缺少版本号。

2>&1认为一切都应该被重定向到stdout,但显然版本号既不在stdout也不stderr

我搜索了类似的问题,在这里找到了一个,其中命令直接输出到$(tty). 但这也不是我的情况。brew cask outdated --greedy &> /dev/null确实消除了所有输出,命令不直接输出到$(tty).

现在我完全糊涂了,那些版本号去哪儿了?

标签: bashmacoshomebrewio-redirectionhomebrew-cask

解决方案


我发现使用script作为一种解决方法来捕获文件中的终端输出在这里可以工作,而不是尝试重定向stdoutstderr.

tmp_file="$(mktemp)"
script -q "$tmp_file" brew cask outdated --greedy >/dev/null
grep -v "(latest)" "$tmp_file" | cut -d " " -f 1
rm "$tmp_file"

推荐阅读