- 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!
- 機器學習實戰:基于Sophon平臺的機器學習理論與實踐
- Introduction to DevOps with Kubernetes
- Julia 1.0 Programming
- Visual C# 2008開發技術實例詳解
- Pig Design Patterns
- 大數據平臺異常檢測分析系統的若干關鍵技術研究
- INSTANT Autodesk Revit 2013 Customization with .NET How-to
- Learn CloudFormation
- 筆記本電腦維修90個精選實例
- 人工智能技術入門
- 學練一本通:51單片機應用技術
- 網絡存儲·數據備份與還原
- Learning Linux Shell Scripting
- Unreal Development Kit Game Design Cookbook
- C#編程兵書