From the course: Cert Prep LPIC-1 Exam 102 (Version 5.0)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Conditional flow with if, then if

Conditional flow with if, then if - Linux Tutorial

From the course: Cert Prep LPIC-1 Exam 102 (Version 5.0)

Start my 1-month free trial

Conditional flow with if, then if

- [ Instructor] Conditionals in Bash are fairly similar to other languages. The syntax looks like this. It can be shortened a bit by placing the then on the same line as the if, separated by a semicolon. If we want to include an else section, we can. We can also check for more than one condition. Note that it checks the condition each time it does an if or elif. This can be slow for a lot of conditions. The condition can be a test of some sort, or it can be the successful execution of a command. This is one thing that separates Bash from other languages. Bash is very tightly integrated with the operating system. In this example, we search etc password for the word root using grep. If it's found in grep, will return a zero to the if conditional and the first code block will run. If grep doesn't find root, then it will return a non-zero number and the second code block will execute. We can negate this result as well. To…

Contents