Up next in 10 CANCEL
PLAY NOW
bash if else if | Use the if..elif..else statement to check multiple condition | bash if statement bash if else if, The if..elif..else statement in Bash is a conditional statement that allows you to check multiple conditions and execute different blocks of code based on the results of the conditions.
The syntax for the if..elif..else statement is as follows:
Bash
if [[ condition1 ]]; then
# code block 1
elif [[ condition2 ]]; then
# code block 2
...
elif [[ conditionN ]]; then
# code block N
else
# code block for the else case
fi
Use code with caution. Learn more
The condition1, condition2, and so on, are any valid Bash expressions. The code blocks are sequences of Bash commands that will be executed if the corresponding condition is true. If none of the conditions are true, the code block for the else case is executed.
Here is an example of a simple Bash if..elif..else statement:
Show More Show Less 1
2:46
Bash Script – File Permissions | File Permissions in Bash Scripting
20K views
·
Aug 14, 2023
2
3:00
Bash Scripting – While Loop | Loops in Scripting
25K views
·
Aug 14, 2023
3
2:02
Bash Scripting – String | Strings in Bash Scripting
14K views
·
Aug 14, 2023
4
2:27
Bash Scripting – Case Statement | Case Statements in Scripting
14K views
·
Aug 14, 2023
5
2:46
Bash Script – Arithmetic Operators | Advanced Arithmetic Operations
22K views
·
Aug 14, 2023
6
2:16
Bash Scripting – Working of Alias | Aliases in Bash Scripting
12K views
·
Aug 15, 2023
7
2:46
Bash Scripting – Substring | Capabilities of Substrings in Bash Scripting
6K views
·
Aug 15, 2023
8
2:12
Bash Script – Working of Bash Variables | Functionality of Variables in Bash Scripting
30K views
·
Aug 15, 2023
9
2:40
Batch Script – Iterating Over an Array | Array Iteration in Batch Scripting
6K views
·
Aug 15, 2023
10
2:16
Bash Script – Read User Input | User Input in Bash Scripting
5K views
·
Aug 15, 2023
11
2:32
Sed Command in LinuxUnix with examples | Advanced 'sed' Commands
10K views
·
Aug 15, 2023
12
1:40
Bash if else if | Bash scripting | Bash scripting capabilities
790 views
·
Aug 17, 2023
13
2:13
Bash if Multiple Conditions | Building on Basic 'if' Statements | Advanced Bash scripting
19K views
·
Aug 17, 2023
14
2:06
bash if -d | the '-d' flag within 'if' statements | '-d' flag in Bash scripting
4K views
·
Aug 17, 2023
15
2:48
if-else in shell script | 'if-else' statements in shell scripting | using 'if-else' constructs
9K views
·
Aug 17, 2023
16
2:44
bash if not | 'if-not' logic in shell scripting | 'if-not' constructs
5K views
·
Aug 17, 2023
17
2:30
bash if -f file | 'if' statement with the '-f' flag | checks in shell scripting
64K views
·
Aug 17, 2023
18
2:06
if-else in shell script example | if-else statements in shell scripting | if-else statements contribute
9K views
·
Aug 17, 2023
19
2:00
shell script if -z option | if -z' option in shell scripting | utilizing the '-z'
9K views
·
Aug 17, 2023
20
2:51
How to Use Shell Scripting in Linux | shell scripting in Linux
25K views
·
Aug 19, 2023
21
1:57
How to Write a Bash Script: A Simple Bash Scripting Tutorial | Bash scripting tutorial for beginners
3K views
·
Nov 9, 2023
22
2:39
How to Rename Files and Directories in Linux | Rename a File in Linux – Bash Terminal Command
2K views
·
Nov 7, 2023
23
3:10
Bash if else Statement | Bash Scripting - Else If Statement | Linux Shell If-Else Syntax Example
2K views
·
Nov 2, 2023
24
2:06
if else in shell script example | Conditions in bash scripting (if statements) | Shell Scripts
198 views
·
Oct 29, 2023
25
1:48
How to Write a Bash Script: A Simple Bash Scripting Tutorial | Shell Scripting Tutorial
6K views
·
Oct 29, 2023
26
1:40
bash if else if | tips for using Bash if..elif..else statements | bash if not in list
2K views
·
Oct 23, 2023
27
3:08
Bash Functions | Bash Scripting - Functions | Bash Functions in Linux | (Bash Reference Manual)
1K views
·
Oct 23, 2023
28
2:46
Bash Script – File Permissions | getting permission to execute a bash script | Create Bash Script
2K views
·
Oct 23, 2023
29
3:29
Bash Functions | Bash Functions Tutorial | BASH Programming | Bash Scripting
2K views
·
Oct 23, 2023
30
2:44
Bash if else Statement | Bash: If, Else If, Else Examples | How to Use if-else in Shell Scripts?
6K views
·
Oct 29, 2023
31
3:00
Bash Scripting – While Loop | Back up your files | Deploy your code to production | Generate reports
788 views
·
Oct 22, 2023
32
2:46
Bash Scripting – Substring | expression returns the length of the string | Call Functions in Bash
1K views
·
Oct 22, 2023
33
2:44
bash if not | Bash if not in linux | Bash if not command | bash if not equal
602 views
·
Oct 22, 2023
1:40
bash if else if | Use the if..elif..else statement to check multiple condition | bash if statement
3K views
·
Oct 22, 2023
35
2:13
Bash if Multiple Conditions | bash if not in list | bash if not empty | Bash if not command line
342 views
·
Oct 23, 2023
36
2:27
Bash Scripting – Case Statement | Bash Case Statement Syntax and Examples
990 views
·
Oct 22, 2023
37
3:29
Bash Functions | bash functions with parameters | bash function return | bash main function
1K views
·
Oct 22, 2023
38
2:23
Bash Shebang | bash function return string | bash call function | bash function example
763 views
·
Oct 22, 2023
39
2:16
Bash Scripting – Working of Alias | if else shell script | bash Functions & Arrays
658 views
·
Oct 22, 2023
40
1:57
Bash scripting tutorial for beginners | bash script | bash scripting | in bash script
3K views
·
Oct 22, 2023
41
2:16
Bash Script – Read User Input | bash script input arguments | bash read user input into variable
986 views
·
Oct 22, 2023
42
2:44
Bash if else Statement | tips for using Bash arithmetic operators | roots and trigonometric function
3K views
·
Oct 22, 2023
43
2:44
bash if not | Bash if not in linux | Bash if not command | bash if not equal
410 views
·
Oct 22, 2023
44
2:30
bash if f file | bash if multiple conditions string comparison | bash if multiple conditions
4K views
·
Oct 22, 2023
45
2:06
bash if d | What is the meaning of `! -d` in this Bash command? | Bash if d command line
1K views
·
Oct 22, 2023