Skip to Content
Learning Linux Shell Scripting - Second Edition
book

Learning Linux Shell Scripting - Second Edition

by Ganesh Sanjiv Naik
May 2018
Beginner
332 pages
7h 28m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting - Second Edition

Using the exit command and the ? variable

If we need to terminate the shell script and come back to the command line, then we can use the exit command. The syntax is very simple:

exit 0 

The given command will terminate the shell script and return to the command line. It will store the 0 value in the ? status variable. We can use any value between 0 and 255. Value 0 means success, and any other non-zero value means an error. We can use these values to indicate error information.

The script to check the value of a parameter that is passed along with the command (either less than 0 or greater than 30) is as follows. This will save us from using the nested if statement:

#!/bin/bash if (( $1 < 0 || $1 > 30 )) then echo "mdays is out of range" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting

Learning Linux Shell Scripting

Ganesh Sanjiv Naik
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788993197Supplemental Content