Play shell script: if select statement _ Case study

2022-06-04 0 By

If conditional test statement syntax structure (single branch) : if [conditional test command]then [command sequence] FI function: Enables the script to automatically execute corresponding commands according to the actual situation.Example: a is 10, b is 20, compare a and B, output: a is less than b[root@localhost~]#vim 1.sh#!/bin/basha=10b=20if [$a -lt $b]then echo “a < b"If [conditional test command]then [command sequence 1]else [command sequence 2] FI Multi-branch structure: if [conditional test command 1]then [command sequence 1]elif [conditional test command 2]then [command sequence 2]else [command sequence 3] FI example:If b is 10, enter a number A, judge the size of a and B, and print the corresponding result./ root @ localhost ~ # vim 1. Sh#!/bin/bashread -p "please enter a:" ab=10if [$a -lt $b]then echo "elif [$a -gt $b]then echo"$a = $b"else echo "$a = $b