- Learning Linux Shell Scripting
- Ganesh Naik
- 171字
- 2021-06-25 22:02:53
The exit status
In shell scripting, we need to check if the last command has successfully executed or not, for example, whether a file or directory is present or not. As per the result, our shell script will continue processing.
For this purpose, the bash shell has one status variable ?. The status of the last command execution is stored in ?. The range of numerical values stored in ? will be from 0 to 255. If successful in execution, then the value will be 0; otherwise, it will be non-zero, which is as follows:
$ ls $ echo $? 0
Here, zero as the return value indicates success.
In the next case, we see the following:
$ ls /root ls: cannot open directory /root: Permission denied $ echo $? 2
Here, a non-zero value indicates an error in the last command execution.
In the next case, we see:
$ find / -name hello.c $ echo $?
The return value will indicate if the hello.c file is present or not!
- 繪制進程圖:可視化D++語言(第1冊)
- 輕松學C#
- Linux Mint System Administrator’s Beginner's Guide
- 協作機器人技術及應用
- 自主研拋機器人技術
- 大數據挑戰與NoSQL數據庫技術
- 21天學通C#
- Windows 7寶典
- Docker on Amazon Web Services
- Mastering Game Development with Unreal Engine 4(Second Edition)
- 簡明學中文版Photoshop
- Microsoft Dynamics CRM 2013 Marketing Automation
- C#編程兵書
- Serverless Design Patterns and Best Practices
- 網站規劃與網頁設計