bash - 将 kubectl 命令输出保存在 Bashscript 的变量中
问题描述
只想将 kubectl 命令的输出保存在 Bash 脚本的变量中。
例如:命令kubectl get all -n mattermost
输出No resources found in mattermost namespace.
foo=$(kubectl get all -n mattermost)
while [ "$foo" = "No resources found in mattermost namespace." ]
do
echo "yay"
done
不幸的是,输出不会保存在变量中..
解决方案
对于像“找不到资源......”这样的消息,它正在 stderr 中打印。要纠正这个问题,您可以将您的行修改为
foo=$(kubectl get all -n mattermost 2>&1)
推荐阅读
- html - 如何将 excel 中的动态编码超链接转换为等效的 HTML 代码?
- docker - 如何以非交互方式调用 docker-compose 运行命令 - SSH?
- angular - 将 Angular 7 项目转换为 Angular 7 库
- mysql - 是否可以在 mysql 的列中使用数学函数?
- listview - 在 Flutter 的 3000 个项目列表中更改项目的状态
- google-cloud-firestore - Firestore 数据库规则 获取文档
- javascript - slideUp/slideDown 滑动两个(全部)子菜单
- javascript - Lodash 查找对象数组
- sass - 如何从变量创建 SASS 映射?
- solr - 在 Apache Solr 中,有没有办法确定核心是否有任何未提交/暂存的更改?