bash - Bash 中的按位运算
问题描述
如何对 Bash 变量进行按位与运算?我想测试程序退出代码中的各个位。就像是:
myprog
BITS=$?
if [ $BITS & 4 ]; then
echo "Bit 2 set"
fi
建议?
解决方案
只需使用 bash 算术扩展:
if (( BITS & 4 )); then
推荐阅读
- amazon-web-services - 如何与组织中的其他用户共享 lambda 函数
- typescript - 与打字相关的接口,但需要的属性不同
- clojure - 在 clojure 中将函数映射到多项 coll 或 seqence 的好方法
- mysql - MariaDB/Mysql SELECT on CASE Statement inside CAST causes an error
- javascript - How do you set Android PrintManager to automatically print 2 copies?
- asp.net-mvc - Application not able to invoke rest call in Win 2016 server, but works fine in Win 10
- sequelize.js - Sequelize 查询参数过滤器中的通配符
- python-3.x - ACL permissions for write_dynamic_frame_from_options in to S3 using AWS Glue
- function - 这条路线有什么问题(“未来”错误)?
- vba - Excel application object seems to "halt" when called in Outlook via VBA