1. Using the If-then statement
Structured command, the primary type is the If-then declaration. If-then For example, the following statement format:
If Commandthen COMMANDSFI
Suppose you are using If-then statements from other programming languages. Such a form may be confusing to you. In other programming languages. The object after the IF statement is an equation to test whether the value is true or false.
Assuming that the command's exit status code is 0 (the command runs successfully), the command in the then section is run. Suppose the exit status code for this command is something else. That then part of the command will not be run, and the bash shell will continue to run the next command in the script.
Here are some simple examples to explain this concept:
$ cat if_then.sh
#!/bin/bashif Test 1 = 2then echo "It worked" fi
At this point the execution if_then will not print ' It worked ', change to such as the following will be found, then after the echo "it worked" will be executed.
#!/bin/bashif Test 1 = 1then echo "It worked" fi
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
If-then and If-then-else statement