summaryrefslogtreecommitdiff
path: root/guides/shell-101.org
blob: b09118bdee5e3acac28f82008b8bc147197cbc57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
My tentative introductory guide to navigating a shell interface
(assuming Bash).

🚧 These are rough notes meant for guiding in-person discussions; they
are somewhat terse. 🚧

* Moving around, invoking stuff

With a file browser and a terminal emulator side-by-side:

- ls, cd, mkdir, touch, rm; "/" = root
- globs
- arguments vs options (e.g. ls, diff)
- man, --help
- standard input/output/error: pipes, redirection
- writing scripts (shebangs: see bash(1) § COMMAND EXECUTION)

* Shell language

- ; & (e.g. sleep)
- && || (e.g. grep)
- if, for
- $? (e.g. grep, diff)
- [
- variables
- functions, $@, $1…
- black-box model of a command:
    - inputs: stdin, arguments, environment
    - outputs: stdout, stderr, exit code
    - side-effects: writing files, connect to network, …
- which, type: keyword ≠ builtin ≠ function ≠ program
- valar quotulis (valar escaepis); e.g. sort operator: [ foo '>' bar ]

* Advanced

- ( ) ≠ { }: try to set variables, or call exit
- (( )), $( )
- glob ≠ regex
- bash extensions
    - [[
    - <( )
    - |&, >&
    - arrays
- job control: fg, bg, jobs, wait, kill, C-z