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 elif clause

The elif clause - Linux Tutorial

From the course: Learning Linux Shell Scripting

Start my 1-month free trial

The elif clause

- [Instructor] There is still one more variation of the if we need to discuss. The elif which is an abbreviation of else if. It allows us to check a different expression than the one used in the if. Elif must come before the else which must be the last clause in the if statement. So, let's modify our script to use the elif. So, right here when we do the first echo, we'll do an elif and now we'll compare again the two numbers, USER_GUESS and this time we'll use a greater than and computer, then we need to put the then clause in and we'll echo you're too high. Then we need to change our else since it's a little bit different. This time we know that you're equal, so we'll just say you've guessed it. And we'll do a control S to save this, go to the terminal and run the script and we'll just say red and 60 and this gives us we're too high. If we say red and 40, we're gonna be too low and if we put it right on 50, you've guessed it and so, that's how we use the elif. Note the elif gets the…

Contents