Difference between revisions of "BASH/C2/Nested-and-multilevel-if-elsif-statements/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 5: Line 5:
 
|-
 
|-
 
| 00:00
 
| 00:00
| Dear friends, welcome to the spoken tutorial on '''Nested '''and''' multilevel if statement''' in '''BASH.'''
+
| Dear friends, welcome to the spoken tutorial on '''Nested and multilevel if statement''' in '''BASH.'''
  
 
|-
 
|-
 
| 00:09
 
| 00:09
|  In this tutorial, we will learn about the
+
|  In this tutorial, we will learn about
  
 
|-
 
|-
Line 17: Line 17:
 
|-
 
|-
 
| 00:14
 
| 00:14
| '''Multilevel if-else statement'''
+
| '''Multilevel if-else statement'''.
  
 
|-
 
|-
Line 29: Line 29:
 
|-
 
|-
 
| 00:28
 
| 00:28
| If not, for relevant tutorials please visit our website which is as shown
+
| If not, for relevant tutorials, please visit our website which is as shown
  
 
|-
 
|-
 
|  00:35
 
|  00:35
|  For this tutorial I am using  
+
|  For this tutorial, I am using  
  
 
|-
 
|-
Line 53: Line 53:
 
|-
 
|-
 
| 00:57
 
| 00:57
| Here, if '''condition1''' is '''true''',''' '''then '''condition 2''' will be evaluated.
+
| Here, if '''condition 1''' is '''True''' then '''condition 2''' will be evaluated,
  
 
|-
 
|-
 
| 01:04
 
| 01:04
|  if '''condition2''' is '''true''', then''' statement 1''' will be executed.
+
|  if '''condition2''' is '''True''' then''' statement 1''' will be executed.
  
 
|-
 
|-
 
| 01:10
 
| 01:10
| That means, only when both the''' conditions''' '''1 '''and '''2 '''are '''true''' , then''' statement 1''' will be executed.
+
| That means, only when both the''' conditions''' 1 and 2 are '''True''' then''' statement 1''' will be executed.
  
 
|-
 
|-
 
| 01:19
 
| 01:19
| If''' condition1''' is '''false, '''then''' statement 3''' will be executed.
+
| If''' condition1''' is '''False, '''then''' statement 3''' will be executed.
  
 
|-
 
|-
 
| 01:25
 
| 01:25
| And if''' condition 2''' is '''false''', then''' statement 2''' will be executed.
+
| And, if''' condition 2''' is '''False''' then''' statement 2''' will be executed.
  
 
|-
 
|-
Line 77: Line 77:
 
|-
 
|-
 
| 01:33
 
| 01:33
| I have written code in the file '''nestedifelse.sh'''
+
| I have written code in the file '''nestedifelse.sh'''.
  
 
|-
 
|-
Line 97: Line 97:
 
|-
 
|-
 
| 01:50
 
| 01:50
| The variable '''PASSWORD '''has been assigned the value '''abc123.'''
+
| The variable '''PASSWORD '''has been assigned the value "abc123".
  
 
|-
 
|-
Line 105: Line 105:
 
|-
 
|-
 
| 02:02
 
| 02:02
| '''- (hyphen) p''' flag displays the '''prompt'''.  
+
| '- (hyphen) p' '''flag''' displays the '''prompt'''.  
  
 
|-
 
|-
 
| 02:05
 
| 02:05
| The string after '''- (hyphen) p, “Enter name: ” '''will be displayed on the '''terminal'''.  
+
| The '''string''' after - (hyphen) p, “Enter name: ” will be displayed on the '''terminal'''.  
  
 
|-
 
|-
Line 117: Line 117:
 
|-
 
|-
 
| 02:18
 
| 02:18
| The first '''if''' statement compares the two variables '''myname '''and '''NAME.'''
+
| The first '''if''' statement compares the two variables '''myname '''and '''NAME '''
  
 
|-
 
|-
 
| 02:24
 
| 02:24
| i.e. the user input and the value stored in variable''' Name '''i.e.''' anusha.'''
+
| i.e. the user input and the value stored in variable''' Name '''i.e. "anusha".
  
 
|-
 
|-
 
| 02:31
 
| 02:31
| If the two values match, then the rest of the code in this '''if statement '''will be evaluated.
+
| If the two values match then the rest of the code in this '''if''' statement will be evaluated.
  
 
|-
 
|-
 
| 02:38
 
| 02:38
| The '''read command''' reads and stores the entered password in variable '''mypassword'''.
+
| The '''read''' command reads and stores the entered password in variable '''mypassword'''.
  
 
|-
 
|-
 
| 02:46
 
| 02:46
| Here, '''- (hyphen) s '''flag is for''' silent mode. '''
+
| Here, '- (hyphen) s' '''flag''' is for''' silent mode. '''
  
 
|-
 
|-
 
| 02:49
 
| 02:49
| It means the text entered by the user will Not be displayed on the '''terminal.'''
+
| It means, the text entered by the user will not be displayed on the '''terminal.'''
  
 
|-
 
|-
 
| 02:56
 
| 02:56
| Here we have another set of '''if-else statements'''.
+
| Here, we have another set of '''if-else statements'''.
  
 
|-
 
|-
 
|  02:59
 
|  02:59
|  This set of '''if-else statements '''is nested within the first '''if '''.
+
|  This set of '''if-else statements '''is nested within the first '''if '''.
  
 
|-
 
|-
Line 153: Line 153:
 
|-
 
|-
 
| 03:12
 
| 03:12
| '''echo''' displays the message''' “Welcome” '''on the '''terminal '''when the '''if condition '''is '''true;'''
+
| '''echo''' displays the message''' “Welcome” '''on the '''terminal '''when the '''if''' '''condition''' is '''True'''
  
 
|-
 
|-
Line 161: Line 161:
 
|-
 
|-
 
| 03:21
 
| 03:21
| '''-e '''enables interpretation of '''backslash escapes.'''
+
| '-e' enables interpretation of '''backslash escape'''.
  
 
|-
 
|-
 
| 03:27
 
| 03:27
| '''\n '''stands for new line; which means the string '''Welcome” '''will be printed on a new line.
+
| '\n' stands for '''new line''' which means the string '''Welcome” '''will be printed on a new line.
  
 
|-
 
|-
 
| 03:35
 
| 03:35
|  When the '''if condition '''is not '''true,'''then the '''else condition '''will be executed;
+
|  When the '''if''' condition is not '''True''' then the '''else''' condition will be executed  
  
 
|-
 
|-
 
| 03:42
 
| 03:42
| i.e. when the passwords don't match, the '''else condition''' will be executed.
+
| i.e. when the passwords don't match, the '''else''' condition will be executed.
  
 
|-
 
|-
 
| 03:48
 
| 03:48
| In this case, '''echo''' displays ''' “Wrong password”'''
+
| In this case, '''echo''' displays ''' “Wrong password”'''.
  
 
|-
 
|-
 
| 03:53
 
| 03:53
|  '''fi '''ends the inner ''' if-else statement.'''
+
|  '''fi '''ends the inner ''' if-else''' statement.
  
 
|-
 
|-
 
| 03:57
 
| 03:57
| Coming back to our first '''if-else statement.'''
+
| Coming back to our first '''if-else statement-'''
  
 
|-
 
|-
 
| 04:01
 
| 04:01
| If the values in '''myname''' and '''NAME''' don't match, then this '''else statement '''will be executed.
+
| if the values in '''myname''' and '''NAME''' don't match then this '''else''' statement will be executed.
  
 
|-
 
|-
Line 197: Line 197:
 
|-
 
|-
 
| 04:14
 
| 04:14
|  '''fi '''ends the outer''' if-else statement.'''
+
|  '''fi '''ends the outer''' if-else''' statement.
  
 
|-
 
|-
 
| 04:18
 
| 04:18
|  Now open the terminal window by pressing '''ctrl+alt and t''' keys simultaneously on your keyboard.
+
|  Now, open the '''terminal window''' by pressing '''ctrl+alt''' and '''t''' keys simultaneously on your keyboard.
  
 
|-
 
|-
Line 213: Line 213:
 
|-
 
|-
 
|  04:38
 
|  04:38
Now type '''dot slash nestedifelse.sh'''
+
Type: '''dot slash nestedifelse.sh'''
  
 
|-
 
|-
Line 221: Line 221:
 
|-
 
|-
 
| 04:46
 
| 04:46
| ie''' Name''' and '''Password'''
+
| i.e '''Name''' and '''Password'''
  
 
|-
 
|-
Line 229: Line 229:
 
|-
 
|-
 
| 04:52
 
| 04:52
|  Here, the '''prompt''' displays '''Enter Name'''
+
|  Here, the '''prompt''' displays '''Enter Name:'''
  
 
|-
 
|-
 
| 04:55
 
| 04:55
|  Let us type '''anusha.'''
+
|  Let us type "anusha".
  
 
|-
 
|-
 
|  04:57
 
|  04:57
|  As this '''condition '''is '''true''', the next '''if condition '''will be evaluated.
+
|  As this '''condition '''is '''True''', the next '''if''' condition will be evaluated.
  
 
|-
 
|-
 
|  05:02
 
|  05:02
|  Now the '''prompt '''says '''Password'''
+
|  Now the '''prompt '''says '''Password'''.
  
 
|-
 
|-
 
|  05:05
 
|  05:05
|  I will type the '''password''' as '''abc123'''
+
|  I will type the password as "abc123".
  
 
|-
 
|-
 
|  05:10
 
|  05:10
|  The''' password '''matches with the value in the variable '''PASSWORD.'''
+
|  The password matches with the value in the variable '''PASSWORD.'''
  
 
|-
 
|-
 
| 05:15
 
| 05:15
|  So, the prompt displays the message '''Welcome'''
+
|  So, the prompt displays the message '''Welcome'''.
  
 
|-
 
|-
Line 261: Line 261:
 
|-
 
|-
 
| 05:21
 
| 05:21
| | Press the up arrow key.  
+
| | Press the 'up-arrow' key.  
  
 
|-
 
|-
Line 273: Line 273:
 
|-
 
|-
 
| 05:31
 
| 05:31
|  This time we will enter the same name, with different password.
+
|  This time, we will enter the same name with different password.
  
 
|-
 
|-
 
| 05:37
 
| 05:37
|  So I will enter the name as '''anusha '''and password as '''123.'''
+
|  So, I will enter the name as "anusha" and password as "123".
  
 
|-
 
|-
Line 293: Line 293:
 
|-
 
|-
 
| 06:01
 
| 06:01
|  Let's execute the script once more.
+
|  Let's '''execute''' the '''script''' once more.
  
 
|-
 
|-
 
| 06:04
 
| 06:04
| This time we will give the name as '''swati '''
+
| This time, we will give the name as "swati".
  
 
|-
 
|-
Line 305: Line 305:
 
|-
 
|-
 
| 06:12
 
| 06:12
| This is because the name '''swati''' does not match the previously declared value '''anusha.'''
+
| This is because the name "swati" does not match the previously declared value "anusha".
  
 
|-
 
|-
 
| 06:19
 
| 06:19
| The control comes out of the first '''if statement''' and executes the '''else statement'''.
+
| The '''control''' comes out of the first '''if''' statement and executes the '''else''' statement.
  
 
|-
 
|-
Line 321: Line 321:
 
|-
 
|-
 
|06:34
 
|06:34
| if ''' condition1''' is '''true,''' then '''statement1''' is executed.
+
| If '''condition1''' is '''True''' then '''statement1''' is executed.
  
 
|-
 
|-
 
| 06:40
 
| 06:40
| If'''condition1''' is '''false''', then''' condition 2''' is evaluated.
+
| If '''condition1''' is '''False''' then''' condition 2''' is evaluated.
  
 
|-
 
|-
 
| 06:46
 
| 06:46
| if '''condition2''' is '''true''', then '''statement 2''' is executed .
+
| If '''condition2''' is '''True''' then '''statement 2''' is executed .
  
 
|-
 
|-
 
| 06:52
 
| 06:52
| And if''' condition 2''' is '''false, '''then''' condition N''' is evaluated.
+
| And if''' condition 2''' is '''False '''then''' condition N''' is evaluated.
  
 
|-
 
|-
 
| 06:58
 
| 06:58
| If''' condition N''' is '''true,''' then''' statement N''' is executed.  
+
| If''' condition N''' is '''True''' then''' statement N''' is executed.  
  
 
|-
 
|-
 
| 07:03
 
| 07:03
| And if''' Condition N''' is '''false,''' then''' statement X''' will be executed.
+
| And if''' Condition N''' is '''false''' then''' statement X''' will be executed.
  
 
|-
 
|-
Line 369: Line 369:
 
|-
 
|-
 
|07:34
 
|07:34
| The '''if condition '''checks whether input string is '''null.'''
+
| The '''if''' condition checks whether input string is '''null.'''
  
 
|-
 
|-
 
| 07:39
 
| 07:39
|'''- (hyphen) z '''checks whether length of '''string''' is '''zero.'''
+
|'- (hyphen) z' checks whether length of '''string''' is '''zero.'''
  
 
|-
 
|-
 
| 07:44
 
| 07:44
|Type '''man test ''' on '''terminal '''and explore various '''string ''' comparison.  
+
|Type: '''man test ''' on '''terminal '''and explore various '''string ''' comparison.  
  
 
|-
 
|-
 
|  07:51
 
|  07:51
|  This '''echo statement ''' will be printed, if nothing is entered.
+
|  This '''echo''' statement  will be printed if nothing is entered.
  
 
|-
 
|-
 
| 07:56
 
| 07:56
|  The first '''elif condition''' checks whether the''' input string''' contains '''raj.'''
+
|  The first '''elif''' condition checks whether the''' input string''' contains "raj".
  
 
|-
 
|-
 
| 08:03
 
| 08:03
|If it does, then this '''echo statement''' will be printed.
+
|If it does then this '''echo''' statement will be printed.
  
 
|-
 
|-
 
| 08:08
 
| 08:08
|The '''wildcard character '''ensures that any word with''' raj '''in it, will be identified.
+
|The '''wildcard character '''ensures that any word with "raj" in it, will be identified.
  
 
|-
 
|-
 
| 08:15
 
| 08:15
|  The next '''elif condition '''checks whether the''' input string''' contains the word '''jit.'''
+
|  The next '''elif''' condition checks whether the''' input string''' contains the word "jit".
  
 
|-
 
|-
 
| 08:22
 
| 08:22
|If it does, then this '''echo statement '''will be printed.
+
|If it does then this '''echo''' statement will be printed.
  
 
|-
 
|-
 
| 08:27
 
| 08:27
| The '''else condition '''will be executed when all the above '''conditions''' fail.
+
| The '''else''' condition will be executed when all the above conditions fail.
  
 
|-
 
|-
 
| 08:33
 
| 08:33
|And it will display the message '''Sorry! Input does not contain either 'raj' or jit'''
+
|And it will display the message '''Sorry! Input does not contain either 'raj' or 'jit'. '''
  
 
|-
 
|-
 
| 08:41
 
| 08:41
|  '''fi''' indicates the end of ''' multilevel if-else''' '''statement.'''
+
|  '''fi''' indicates the end of ''' multilevel if-else''' statement.
  
 
|-
 
|-
 
|  08:46
 
|  08:46
|  Let us now execute the program.
+
|  Let us '''execute''' the program.
  
 
|-
 
|-
Line 449: Line 449:
 
|-
 
|-
 
| 09:22
 
| 09:22
|And the control comes out of the '''multilevel if-else statement.'''
+
|And the '''control''' comes out of the '''multilevel if-else statement.'''
  
 
|-
 
|-
 
| 09:28
 
| 09:28
| Let me clear the prompt.
+
| Let me clear the '''prompt'''.
  
 
|-
 
|-
Line 461: Line 461:
 
|-
 
|-
 
| 09:34
 
| 09:34
|Press up arrow key.
+
|Press 'up-arrow' key.
  
 
|-
 
|-
Line 477: Line 477:
 
|-
 
|-
 
| 09:45
 
| 09:45
|I will type '''abhijit.'''
+
|I will type "abhijit".
  
 
|-
 
|-
 
| 09:48
 
| 09:48
|  The output displayed is '''“abhijit contains word jit”.'''
+
|  The output displayed is: '''“abhijit" contains word 'jit'.'''
  
 
|-
 
|-
 
| 09:53
 
| 09:53
|This shows that the control flowed to the third '''condition''' in our code.
+
|This shows that the '''control''' flowed to the third '''condition''' in our code.
  
 
|-
 
|-
 
| 09:59
 
| 09:59
|The first two '''conditions''' did not match.
+
|The first two conditions did not match.
  
 
|-
 
|-
 
|10:03
 
|10:03
| The same logic is applicable for all the '''conditions.'''
+
| The same logic is applicable for all the conditions.
  
 
|-
 
|-
Line 501: Line 501:
 
|-
 
|-
 
| 10:13
 
| 10:13
|Let us summarise.
+
|Let us summarize.
  
 
|-
 
|-
 
| 10:15
 
| 10:15
|In this tutorial we learnt, the usage of
+
|In this tutorial, we learned the usage of:
  
 
|-
 
|-
 
| 10:18
 
| 10:18
| '''Nested If-else:''' with ''' Name''' and''' Password verification''' and
+
| '''Nested if-else:''' with ''' Name''' and''' Password''' verification and
  
 
|-
 
|-
 
| 10:23
 
| 10:23
|'''Multilevel if-else: String comparison''' program
+
|'''Multilevel if-else: '''String comparison''' program.
  
 
|-
 
|-
Line 521: Line 521:
 
|-
 
|-
 
| 10:34
 
| 10:34
| greater than 3,
+
|* greater than 3
  
 
|-
 
|-
 
| 10:35
 
| 10:35
| lesser than 3,
+
|* lesser than 3
  
 
|-
 
|-
 
| 10:37
 
| 10:37
| or equal to 3,
+
|* or equal to 3
  
 
|-
 
|-
 
| 10:39
 
| 10:39
|or when the user input is empty
+
|or when the user input is empty.
  
 
|-
 
|-
 
| 10:42
 
| 10:42
| Watch the video available at the link shown below
+
| Watch the video available at the link shown below.
  
 
|-
 
|-
 
| 10:45
 
| 10:45
|It summarizes the Spoken Tutorial project  
+
|It summarizes the Spoken Tutorial project.
  
 
|-
 
|-
 
| 10:48
 
| 10:48
|If you do not have good bandwidth, you can download and watch it
+
|If you do not have good bandwidth, you can download and watch it.
  
 
|-
 
|-
 
| 10:53
 
| 10:53
|  The Spoken Tutorial Project Team  
+
|  The Spoken Tutorial Project Team:
  
 
|-
 
|-
 
| 10:55
 
| 10:55
|Conducts workshops using spoken tutorials  
+
|* Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
| 10:58
 
| 10:58
|Gives certificates to those who pass an online test  
+
|* Gives certificates to those who pass an online test.
  
 
|-
 
|-
Line 565: Line 565:
 
|-
 
|-
 
| 11:09
 
| 11:09
| Spoken Tutorial Project is a part of the Talk to a Teacher project
+
|''' Spoken Tutorial''' project is a part of the '''Talk to a Teacher''' project.
  
 
|-
 
|-
 
| 11:13
 
| 11:13
|It is supported by the National Mission on Education through ICT, MHRD, Government of India
+
|It is supported by the National Mission on Education through ICT, MHRD, Government of India.
  
 
|-
 
|-
 
| 11:20
 
| 11:20
|More information on this Mission is available at the link shown below
+
|More information on this mission is available at the link shown below.
  
 
|-
 
|-
 
|11:26
 
|11:26
| The script has been contributed by FOSSEE and Spoken Tutorial Team.
+
| The script has been contributed by FOSSEE and Spoken Tutorial teams.
  
 
|-
 
|-

Revision as of 18:08, 10 July 2015

Time
Narration
00:00 Dear friends, welcome to the spoken tutorial on Nested and multilevel if statement in BASH.
00:09 In this tutorial, we will learn about:
00:12 Nested if-else and
00:14 Multilevel if-else statement.
00:17 We will do this by using a few examples.
00:22 To follow this tutorial, You should be familiar with Linux Operating System.
00:28 If not, for relevant tutorials, please visit our website which is as shown
00:35 For this tutorial, I am using
00:38 Ubuntu Linux 12.04 OS and
00:42 GNU Bash version 4.1.10
00:46 GNU Bash version 4 or above is recommended for practice.
00:52 Let us understand the flow of Nested if-else statement.
00:57 Here, if condition 1 is True then condition 2 will be evaluated,
01:04 if condition2 is True then statement 1 will be executed.
01:10 That means, only when both the conditions 1 and 2 are True then statement 1 will be executed.
01:19 If condition1 is False, then statement 3 will be executed.
01:25 And, if condition 2 is False then statement 2 will be executed.
01:31 Let's see an example.
01:33 I have written code in the file nestedifelse.sh.
01:38 I will open it.
01:40 Let me explain the code now.
01:43 This is the shebang line.
01:45 The variable NAME has been assigned the value anusha.
01:50 The variable PASSWORD has been assigned the value "abc123".
01:56 The read command reads one line of data from the standard input.
02:02 '- (hyphen) p' flag displays the prompt.
02:05 The string after - (hyphen) p, “Enter name: ” will be displayed on the terminal.
02:11 myname is a variable which stores the text entered by user i.e. the user input.
02:18 The first if statement compares the two variables myname and NAME
02:24 i.e. the user input and the value stored in variable Name i.e. "anusha".
02:31 If the two values match then the rest of the code in this if statement will be evaluated.
02:38 The read command reads and stores the entered password in variable mypassword.
02:46 Here, '- (hyphen) s' flag is for silent mode.
02:49 It means, the text entered by the user will not be displayed on the terminal.
02:56 Here, we have another set of if-else statements.
02:59 This set of if-else statements is nested within the first if .
03:05 The second if statement compares variables mypassword and PASSWORD.
03:12 echo displays the message “Welcome” on the terminal when the if condition is True
03:18 i.e. the passwords match.
03:21 '-e' enables interpretation of backslash escape.
03:27 '\n' stands for new line which means the string Welcome” will be printed on a new line.
03:35 When the if condition is not True then the else condition will be executed
03:42 i.e. when the passwords don't match, the else condition will be executed.
03:48 In this case, echo displays “Wrong password”.
03:53 fi ends the inner if-else statement.
03:57 Coming back to our first if-else statement-
04:01 if the values in myname and NAME don't match then this else statement will be executed.
04:09 This will echo the message “Wrong Name” on the terminal.
04:14 fi ends the outer if-else statement.
04:18 Now, open the terminal window by pressing ctrl+alt and t keys simultaneously on your keyboard.
04:27 Make the file executable.
04:29 Type: chmod space plus x space nestedifelse.sh
04:38 Type: dot slash nestedifelse.sh
04:43 The program verifies two conditions
04:46 i.e Name and Password
04:48 when it is executed on the terminal.
04:52 Here, the prompt displays Enter Name:
04:55 Let us type "anusha".
04:57 As this condition is True, the next if condition will be evaluated.
05:02 Now the prompt says Password.
05:05 I will type the password as "abc123".
05:10 The password matches with the value in the variable PASSWORD.
05:15 So, the prompt displays the message Welcome.
05:19 Now let us execute the script again.
05:21 Press the 'up-arrow' key.
05:24 Go to dot slash nestedifelse.sh
05:29 Press Enter.
05:31 This time, we will enter the same name with different password.
05:37 So, I will enter the name as "anusha" and password as "123".
05:44 The name values will match but the password values won't.
05:49 So, the message Wrong passwordwill be displayed.
05:53 This proves that the nested else statement within the first if statement was executed.
06:01 Let's execute the script once more.
06:04 This time, we will give the name as "swati".
06:08 The message “Wrong name” is displayed.
06:12 This is because the name "swati" does not match the previously declared value "anusha".
06:19 The control comes out of the first if statement and executes the else statement.
06:25 This prints the message Wrong name.
06:29 Now let us look at multilevel if-else statement.
06:34 If condition1 is True then statement1 is executed.
06:40 If condition1 is False then condition 2 is evaluated.
06:46 If condition2 is True then statement 2 is executed .
06:52 And if condition 2 is False then condition N is evaluated.
06:58 If condition N is True then statement N is executed.
07:03 And if Condition N is false then statement X will be executed.
07:10 Let's look at an example.
07:12 I have a working example.
07:14 I will open it. Note that our file name is multilevel hyphen ifelse dot sh.
07:23 Let us go through the code.
07:25 This is the shebang line.
07:27 mystring is a variable which stores the word, input by user, during execution.
07:34 The if condition checks whether input string is null.
07:39 '- (hyphen) z' checks whether length of string is zero.
07:44 Type: man test on terminal and explore various string comparison.
07:51 This echo statement will be printed if nothing is entered.
07:56 The first elif condition checks whether the input string contains "raj".
08:03 If it does then this echo statement will be printed.
08:08 The wildcard character ensures that any word with "raj" in it, will be identified.
08:15 The next elif condition checks whether the input string contains the word "jit".
08:22 If it does then this echo statement will be printed.
08:27 The else condition will be executed when all the above conditions fail.
08:33 And it will display the message Sorry! Input does not contain either 'raj' or 'jit'.
08:41 fi indicates the end of multilevel if-else statement.
08:46 Let us execute the program.
08:48 Come back to our terminal.
08:51 Type: chmod space plus x space multilevel hyphen ifelse dot sh
09:00 Type dot slash multilevel hyphen ifelse dot sh
09:06 We are prompted for an input.
09:09 Let us give different inputs and see what happens each time.
09:14 First I will press Enter without typing anything.
09:19 The message Nothing was Entered is displayed.
09:22 And the control comes out of the multilevel if-else statement.
09:28 Let me clear the prompt.
09:30 Let us try executing the script with a different input.
09:34 Press 'up-arrow' key.
09:36 Go to dot slash multilevel hyphen ifelse dot sh.
09:41 Press Enter.
09:43 The prompt displays "Enter a Word".
09:45 I will type "abhijit".
09:48 The output displayed is: “abhijit" contains word 'jit'.
09:53 This shows that the control flowed to the third condition in our code.
09:59 The first two conditions did not match.
10:03 The same logic is applicable for all the conditions.
10:07 Try executing the program with different inputs and check the results.
10:13 Let us summarize.
10:15 In this tutorial, we learned the usage of:
10:18 Nested if-else: with Name and Password verification and
10:23 Multilevel if-else: String comparison program.
10:28 As an assignment, write a program to output different messages when number is
10:34 * greater than 3
10:35 * lesser than 3
10:37 * or equal to 3
10:39 or when the user input is empty.
10:42 Watch the video available at the link shown below.
10:45 It summarizes the Spoken Tutorial project.
10:48 If you do not have good bandwidth, you can download and watch it.
10:53 The Spoken Tutorial Project Team:
10:55 * Conducts workshops using spoken tutorials.
10:58 * Gives certificates to those who pass an online test.
11:02 For more details, please write to contact@spoken-tutorial.org
11:09 Spoken Tutorial project is a part of the Talk to a Teacher project.
11:13 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
11:20 More information on this mission is available at the link shown below.
11:26 The script has been contributed by FOSSEE and Spoken Tutorial teams.
11:31 This is Ashwini from IIT Bombay.

Thank you for joining.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14