Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 49953ef

Browse files
authored
Added elif statement with an example (#64)
Added a small contribution of `elif` statement in the case of multiple conditions.
1 parent 5873e5c commit 49953ef

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎ebook/en/content/010-bash-conditionals.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ else
9696
fi
9797
```
9898

99+
If you have multiple conditions and scenerios, then can use `elif` statement with `if` and `else` statements.
100+
101+
```bash
102+
#!/bin/bash
103+
104+
read -p "Enter a number: " num
105+
106+
if [[ $num -gt 0 ]] ; then
107+
echo "The number is positive"
108+
elif [[ $num -lt 0 ]] ; then
109+
echo "The number is negative"
110+
else
111+
echo "The number is 0"
112+
fi
113+
```
114+
99115
## Switch case statements
100116

101117
As in other programming languages, you can use a `case` statement to simplify complex conditionals when there are multiple different choices. So rather than using a few `if`, and `if-else` statements, you could use a single `case` statement.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /