From the course: Learning Linux Shell Scripting

Unlock the full course today

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

The else clause

The else clause - Linux Tutorial

From the course: Learning Linux Shell Scripting

Start my 1-month free trial

The else clause

- [Instructor] Sometimes you'd like to do one thing if the expression is true and something else if it is false. That is where the else clause comes in. If the expression is false, then the commands following the else up to the fi are executed. And if it is true, it executes the commands in between the then and the else. So, let's go ahead and add the else to our script and we're gonna come in here and right after the echo, we'll say else and we're gonna echo out the color is NOT blue and here with our number comparison, we'll say else and we'll echo and there's actually two possibilities here. You're equal or too high. And we'll do a control S to save that. Go back down to the terminal. Let's go ahead and just clear the screen. And we will say if.sh and this time we'll type the color blue and we'll put in the number 45. So, we get the color is blue, you're too low, and this time we'll try blue again but we'll change the number to 55 which we know is too high and we get the color is…

Contents