bash - 保留美元?使用文件描述符使用多个管道语句输出
问题描述
解决方案
I suspect this is all you really need:
cmd=$(uname -a | awk '{print $1; f=1} END{exit !f}')
echo "$?"
That will exit with status 0 if uname produces any output and awk succesfully reads/prints it, 1 otherwise.
Look:
$ cmd=$(uname -a | awk '{print $1; f=1} END{exit !f}')
$ echo "$?"
0
$ cmd=$(uname + -a | awk '{print $1; f=1} END{exit !f}')
uname: extra operand ‘+’
Try 'uname --help' for more information.
$ echo "$?"
1
推荐阅读
- node.js - javascript 对象的查询字符串
- python - 计算销售额滚动(滞后和领先)差异的最佳方法是什么?
- c# - 扩展 LINQ 表达式
- google-apps-script - 脚本有效负载数据中的自动登录未正确编码 - 有没有办法解决这个问题?
- c++ - 我正在编写单元测试。如何修复 LNK1120 错误
- c# - 无法使用进程执行多个命令/参数
- java - 有没有办法在不将帐户添加到设备的情况下使用 Google 登录?
- django - 在Django的视图中序列化数据时如何指定为外部字段返回哪个值
- chez-scheme - 在 Chez Scheme 中重新导入库
- keras - SIMPLERNN KERAS 中的矩阵计算