当前位置:网站首页>shell判断命令是否执行成功
shell判断命令是否执行成功
2022-06-29 10:57:00 【识途老码】
shell判断命令是否执行成功
判断上条命令是否成功
#!/usr/bin/env bash
# 该脚本用于演示: 判断上条命令是否成功
# 上一条命令是否不等于0
if [ $? -ne 0 ]; then
echo "failed"
else
echo "succeed"
fi
# 上一条命令状态是否等于0
if [ $? -eq 0 ]; then
echo "succeed"
else
echo "failed"
fi
# 建议的代码风格: 如果命令未执行成,就打印执行失败
if ! make mytarget; then
echo "Build failed"
fi
shell比较运算符
参考: https://blog.mimvp.com/article/7415.html
| 运算符 | 解释 |
|---|---|
| -eq | 等于 |
| -ne | 不等于 |
| -gt | 大于 |
| -lt | 小于 |
| ge | 大于等于 |
| le | 小于等于 |
边栏推荐
- 又拍云 Redis 的改进之路
- [daily 3 questions (1)] judge the color of a grid on the chess board
- 如何识别出轮廓准确的长和宽
- Qt学习07 Qt中的坐标系统
- 分布式缓存之Memcached
- 海泰前沿技术|隐私计算技术在医疗数据保护中的应用
- 申请uniapp离线打包时的AppKey
- Oracle扩充分布式云端服务 为更多客户带来全面公有云服务
- What are the main factors that affect the heat dissipation of LED packaging?
- Object class - the father of ten thousand classes
猜你喜欢

关于IP定位查询接口的测评Ⅱ

软件工程导论——第五章——总体设计

在日本的 IT 公司工作是怎样一番体验?

美创入选信通院“业务安全推进计划”首批成员单位

信息技术应用创新专业人员(数据库)中级培训火热招生中(7月6-10日)

How to identify the exact length and width of the contour

Live broadcast by technical experts from China Kuwait Fangde: how to build a private cloud platform based on openstack and CEPH| Issue 27

Oracle NetSuite 助力 TCM Bio,洞悉数据变化,让业务发展更灵活

新版CorelDRAW Technical Suite2022最新详细功能介绍

Design and implementation of IDS
随机推荐
(JS) array methods: slice and slice
Qt学习03 Qt的诞生和本质
Introduction to software engineering - Chapter 5 - overall design
基于鲲鹏开发套件实现x86平台到Kunpeng平台的源码迁移【玩转华为云】
2022胺基化工艺考试题模拟考试题库及在线模拟考试
[3 questions per day (2)] minimum operand for generating alternate binary strings
Oracle expands distributed cloud services to bring comprehensive public cloud services to more customers
Adding sharding sphere5.0.0 sub tables to the ruoyi framework (adding custom sub table policies through SPI)
Record once MSI notebook ge63 plays webpage video flash screen and randomly turns green to solve the problem
QT learning 09 calculator interface code reconstruction
信息技术应用创新专业人员(数据库)中级培训火热招生中(7月6-10日)
【HBZ分享】Semaphore 与 CountDownLatch原理
c# 键盘钩子
稳定币风险状况:USDT 和 USDC 安全吗?
Qt学习07 Qt中的坐标系统
How to test the performance of container platform, including stability, expansion efficiency and component performance
Qt学习08 启航!第一个应用实例
STM32看门狗研究
MySQL 索引失效的几种类型以及解决方式
Exclusive interview with head of suss NIFT: the future of Web3 is inseparable from the governance of "everyone for me, I for everyone"