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

Added elif statement with an example #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
bobbyiliev merged 1 commit into bobbyiliev:main from Nirzak:patch-1
Oct 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ebook/en/content/010-bash-conditionals.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ else
fi
```

If you have multiple conditions and scenerios, then can use `elif` statement with `if` and `else` statements.

```bash
#!/bin/bash

read -p "Enter a number: " num

if [[ $num -gt 0 ]] ; then
echo "The number is positive"
elif [[ $num -lt 0 ]] ; then
echo "The number is negative"
else
echo "The number is 0"
fi
```

## Switch case statements

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.
Expand Down

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