2. Control Flow Structure
Exit status
While, for, and until loops Loops
If then else statement
Actions in the script
Menu
1. Exit
An exit status is returned when any command is running. To observe the exit status, run the following command:
$ Echo $?
To exit the current process, shell provides the exit command in the following format:
Exit n, where n is a number
2. Control Structure
2.1 Flow Control
If, then, and else statements provide conditional tests. However, based on various conditions
Case statements allow matching modes, words, or values
2.2 cycles
For Loop
Until Loop
While Loop
3 if then else statement
If condition
Then command
Fi
When using the if statement, you must place the then part in the new line; otherwise, an error occurs. If you want to remove a branch, you must use the command delimiter:
If condition; then
Command
Fi
Echo-n "Enter you name :"
Read name
If [$ name = ""]; then
Echo "You did not enter any information"
Fi
Grep output check
$ PG grepif
#! /Bin/sh
# Grepif
If grep 'Dave \> 'data. File>/dev/null 2> & 1
Then
Echo "Great Dave is in the file"
Else
Echo "no Dave is not in the file"
Fi
Parameters passed to the script for test
$ # Indicates the number of parameters
Determines whether the script is in interactive mode.
Sometimes you need to know whether script execution is in interactive mode (Terminal Mode) or non-interactive mode (cron or)