Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bash Programming Cheatsheet
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Junier
Bash Programming Cheatsheet
Commits
370957da
Commit
370957da
authored
Dec 11, 2020
by
Thomas Junier
Browse files
Options
Downloads
Patches
Plain Diff
rewrote if-thrn-else
parent
89e07750
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bash_prog_ref.md
+17
-16
17 additions, 16 deletions
bash_prog_ref.md
with
17 additions
and
16 deletions
bash_prog_ref.md
+
17
−
16
View file @
370957da
...
...
@@ -285,22 +285,23 @@ Loop control: `break [n]`, `continue [n]`
Conditionals
------------
### `if - then - else`
```
bash
if
cmd1
;
then
list1
;
# iff cmd1 succeeds
elif
cmd2
;
then
list1
;
# iff cmd1 fails but cmd2 succeeds
else
alt
;
# otherwise
fi
```
`cmd?`
may be _any_ commands (often
`(())`
or
`[[]]`
);
`list?`
and
`alt`
are lists.
There are $
\g
eq 0$
`elif`
clauses, and $
\l
eq 1$
`else`
clause.
### _if - then - else_
|
`if`
_
`test-list1`
_
`;`
`then`
| _
`consequent-list1`
_
`;`
|
`elif`
_
`test-list2`
_
`;`
`then`
| _
`consequent-list2`
_
`;`
|
`else`
| _
`alt-list`
_
`;`
|
`fi`
_`consequent-list`_
_n_ is executed iff _
`test-list`
_ _
n_ succeeds; _
`alt-list`
_
is executed if none of the _
`test-list`
_s succeeds.
\
_`test-list?`_
is often a
`(())`
or
`[[]]`
conditional but may be _any_ lists,
including a simple command.
The
`else`
and
`elif`
clauses are optional, there may be more than one
`elif`
clause.
### `case - in`
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment