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
f76775e6
Commit
f76775e6
authored
Jan 14, 2021
by
Thomas Junier
Browse files
Options
Downloads
Patches
Plain Diff
italics around nonliteral []*?
parent
5fef1a15
Branches
Branches containing commit
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
+40
-10
40 additions, 10 deletions
bash_prog_ref.md
with
40 additions
and
10 deletions
bash_prog_ref.md
+
40
−
10
View file @
f76775e6
...
...
@@ -5,11 +5,11 @@ geometry:
colorlinks
:
on
---
Preamble
Notation
========
Roman
`[ ] *`
stand for themselves;
when
in italics they denote
one or
more _
`[`
_ optional
elements _
`]`
_ (0 or 1) or indicate repetition (_
`*`
_).
Roman
`[ ] *`
stand for themselves; in italics they denote
_
`[`
_ optional
elements _
`]`
_ (0 or 1) or indicate repetition (_
`*`
_)
($
\g
eq 1$)
.
Operation
=========
...
...
@@ -41,12 +41,12 @@ Parsing
The tokens are split into commands, of which there are the following four kinds:
*
Simple commands: _
`[`
_`assignment`_
`*]`
_ `program` _
`[`
_`arg`_
`*] [`
_`&`_
`]`
_
*
Pipelines:
`cmd
[
| cmd]*`
(or
`|&`
to redirect
`stderr`
too)
*
Pipelines:
`cmd
`
_
`[`
_`
| cmd
`_
`
]*`
_
(or
`|&`
to redirect
`stderr`
too)
*
Lists: $
\g
eq 1$ pipelines; precedence:
`&&`
,
`||`
;
`&`
,
`;`
*
`ppln1
[
&& ppln2]`
2 iff 1 succeeds
*
`ppln1
[
|| ppln2]`
2 iff 1 fails
*
`ppln1
[
; ppln2]`
2 waits for 1
*
`ppln1
[
& ppln2
]
`
doesn't wait (bg)
*
`ppln1
`
_
`[`
_`
&& ppln2
`_
`
]`
_
2 iff 1 succeeds
*
`ppln1
`
_
`[`
_`
|| ppln2
`_
`
]`
_
2 iff 1 fails
*
`ppln1
`
_
`[`
_`
; ppln2
`_
`
]`
_
2 waits for 1
*
`ppln1
`
_
`[`
_
`
& ppln2`
]]
doesn't wait (bg)
*
Compound commands:
*
Loops
*
Conditionals
...
...
@@ -68,9 +68,39 @@ Expansions
## Brace Expansion
special
`[]*`
A prefix and suffix (both possibly empty) are affixed to each
of a list of strings. This is either an explicit list, or a sequence.
1.
Brace:
`{X,Y[,Z]*}`
;
`{x..y[..step]}`
### `{,}` List
Generate lists of strings, normally with a common prefix, suffix, or both.
\b
egin{tabular}{p{2.5cm}p{3.5cm}p{4cm}}
\t
extbf{expansion} &
\t
extbf{value} &
\t
extbf{comment}
\\
\t
exttt{pr
\{
A,B,C
\}
} &
\t
exttt{prA prB prC} & prefix
\\
\t
exttt{
\{
A,B,C
\}
su} &
\t
exttt{Asu Bsu Csu} & suffix
\\
\t
exttt{pr
\{
A,B,C
\}
su} &
\t
exttt{prAsu prBsu prCsu} & both
\e
nd{tabular}
### `{..}` Sequence
Generate sequences, possibly with a common prefix, suffix, or both. Specify
start, stop, and an optional step.
\b
egin{tabular}{p{2.0cm}p{4cm}p{4cm}}
\t
extbf{expansion} &
\t
extbf{value} &
\t
extbf{comment}
\\
\t
exttt{
\{
1..5
\}
} &
\t
exttt{1 2 3 4 5} &
\\
\t
exttt{f
\{
1..4
\}
.c} &
\t
exttt{f1.c f2.c f3.c f4.c} & affixes
\\
\t
exttt{
\{
5..1
\}
} &
\t
exttt{5 4 3 2 1} & reverse
\\
\t
exttt{
\{
01..5
\}
} &
\t
exttt{01 02 03 04 05} & fixed width
\\
\t
exttt{
\{
1..10..2
\}
} &
\t
exttt{1 3 5 7 9} & step
\\
\t
exttt{
\{
a..e
\}
} &
\t
exttt{a b c d e} & character
\e
nd{tabular}
Nesting is possible:
`{a,b,c{1..3}}`
$
\r
ightarrow$
` a b c1 c2 c3`
**Note**
: contrary to _filename expansion_, the generated strings do _not_ have to match
filenames.
Tilde Expansion
---------------
...
...
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