bash - 无法重定向所有自制桶过时的输出?
问题描述
我正在编写一个脚本来确定要升级哪些过时的木桶,因为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)
.
现在我完全糊涂了,那些版本号去哪儿了?
解决方案
我发现使用script
作为一种解决方法来捕获文件中的终端输出在这里可以工作,而不是尝试重定向stdout
或stderr
.
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"
推荐阅读
- javascript - Firestore分页以错误的顺序附加数组
- c - How get proper warnings using Cygwin C compiler on Eclipse IDE
- javascript - 如何使用 react-flip-move 为表格设置动画
- r - 来自 SFTP 连接的 R 文件信息
- sql - 如何将一个表中的数据插入到另一个表中?
- node.js - Twilio 视频连接时间
- javascript - 如何在javascript中将单个对象拆分为不同的数组?
- python - 如何从查询集字典类型的模板将参数传递给自定义模板标签
- android - 标题对齐
- sql - Pass Variable from View in LIMIT clause in Bigquery