Skip to content

Commit b0ba2be

Browse files
committed
content: finished git-intro, minor clean-up
1 parent f94b89a commit b0ba2be

File tree

8 files changed

+126
-64
lines changed

8 files changed

+126
-64
lines changed

src/content/lessons/basic-bash.md

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Bash is a Turing-complete language and provides a large variety of features.
1717
---
1818

1919
Some of them are common to most popular programming languages:
20+
2021
- variables
2122
- conditional statements
2223
- loops
@@ -27,6 +28,7 @@ Some of them are common to most popular programming languages:
2728
---
2829

2930
Others are specific to bash and the terminal environment:
31+
3032
- pipes
3133
- job controls
3234
- shell expansions
@@ -53,14 +55,17 @@ Bash can be used either:
5355
## Interactive mode
5456

5557
This is an example of a minimal prompt.
58+
5659
```bash
57-
$
60+
$
5861
```
62+
5963
It signifies that the shell is ready to accept commands.
6064

6165
<bonus-content>
6266

6367
The prompt can be customized to include any desirable information such as:
68+
6469
- the current directory
6570
- the machine name
6671
- the current user
@@ -81,38 +86,58 @@ The prompt can be customized to include any desirable information such as:
8186

8287
echo 'Hello World!'
8388
```
89+
8490
Once the user submits the command, it executes, and prints the output to the screen.
8591

86-
The `echo` command prints the provided argument to **standard out**
92+
The `echo` command prints the provided argument to __standard out__
8793

8894
---
8995

9096
> *Beware*: Bash is case-sensitive, so trying
97+
>
9198
> ```bash
9299
>EcHo 'hello world'
93100
>```
101+
>
94102
>might NOT produce the expected result
95103
96104
---
97105
98106
## Anatomy of a command
99107
100108
All commands in bash follow the following general structure:
109+
101110
```bash
102111
[variables] [command] [options] [arguments] [redirects] [operators]
103112
```
113+
104114
The command is the only mandatory element, everything else is optional
105115

116+
<bonus-content>
117+
118+
## Command parsing order
119+
120+
Bash processes commands in this order:
121+
122+
1. History expansion (if enabled)
123+
2. Quote removal and word splitting
124+
3. Expansions (brace, tilde, parameter, arithmetic, command substitution, pathname)
125+
4. Redirection setup
126+
5. Command execution
127+
128+
</bonus-content>
129+
106130
---
107131

108132
## Output
109133

110134
There are 2 main output streams:
111-
- standard output (**stdout**) for regular program output
112135

113-
- standard error (**stderr**) for error messages and diagnostics.
136+
- standard output (__stdout__) for regular program output
137+
138+
- standard error (__stderr__) for error messages and diagnostics.
114139

115-
> **By default, both streams are displayed on the terminal.**
140+
> __By default, both streams are displayed on the terminal.__
116141
117142
---
118143

@@ -121,6 +146,7 @@ There are 2 main output streams:
121146
There are several types of commands in bash.
122147

123148
When trying to execute a command bash will search for it in this order:
149+
124150
- aliases
125151
- keywords
126152
- functions
@@ -130,6 +156,7 @@ When trying to execute a command bash will search for it in this order:
130156
---
131157

132158
Use the `type` built-in command to check the type of another command.
159+
133160
```bash
134161
type grep
135162
# prints: grep is /usr/bin/grep
@@ -149,25 +176,26 @@ type ll
149176
### Built-ins and keywords
150177
151178
Use the `help` command to get basic information about built-ins and keywords.
179+
152180
```bash
153181
help # prints all built-ins and keywords
154182

155183
help if # prints information about the if keyword
156184
```
157185
158-
159186
---
160187
161188
### Aliases
162189
163190
Use the `alias` command to view or define aliases.
191+
164192
```bash
165193
alias # prints all aliases
166194

167195
alias ll='ls -alh' # define a new alias
168196
```
169197
170-
> **NOTE**: there must be NO spaces around the `=` sign.
198+
> __NOTE__: there must be NO spaces around the `=` sign.
171199
> Also, unlike other languages, bash handles single and double quotes differently.
172200
173201
---
@@ -223,6 +251,7 @@ Fortunately, bash provides a special variable `$?` to indicate the exit status o
223251
---
224252
225253
A value of `0` means success. Any other (positive number) indicates an error.
254+
226255
```bash
227256
type ls
228257
echo $?
@@ -239,6 +268,7 @@ echo $?
239268
<pop-quiz data-answer-id="2">
240269
241270
### Which is *NOT* a valid command type?
271+
242272
- built-in
243273
- file (external)
244274
- interactive
@@ -264,10 +294,12 @@ echo $?
264294
Use the `env` command to see all variables defined on the system.
265295
266296
Or `echo` to print the value of a specific variable:
297+
267298
```bash
268299
echo $BASH_VERSION
269300
# prints: bash-5.3
270301
```
302+
271303
> NOTICE the `$` character used to reference the variables
272304
273305
---
@@ -282,6 +314,7 @@ MY_VAR='hello' fruit='banana'
282314
echo $fruit $MY_VAR
283315
# prints: banana hello
284316
```
317+
285318
> NOTICE there is NO `$` character when defining variables.
286319
287320
<bonus-content>
@@ -332,7 +365,7 @@ echo $TZ
332365
333366
---
334367
335-
The `$` character is used for **variable expansion**.
368+
The `$` character is used for __variable expansion__.
336369
337370
It allows multiple advanced features:
338371
@@ -356,6 +389,7 @@ echo ${my_var:1:3}
356389
## Single vs double quotes
357390
358391
Single quotes denote a literal string, while double quotes allow for variable expansion.
392+
359393
```bash
360394
echo '$MY_VAR test'
361395
# prints: $MY_VAR test
@@ -374,6 +408,7 @@ echo "$MY_VAR test"
374408
375409
By default, the output of a command goes to stdout. But there are ways to redirect or capture
376410
the result of a command:
411+
377412
```bash
378413
today=date
379414
echo $today
@@ -387,9 +422,10 @@ echo $today
387422
---
388423
389424
Subshells can also be used to pass the output of one command as an argument to another:
425+
390426
```bash
391427
du -h $(which ls)
392-
# print: 40K /bin/ls
428+
# print: 40K /bin/ls
393429
```
394430
395431
- `du` returns the size of a file
@@ -406,7 +442,7 @@ env | grep MY_
406442
# prints all global variables that contain the string MY_
407443
```
408444
409-
Using a pipe we are redirecting the output of the first command to the **stdin** of the second.
445+
Using a pipe we are redirecting the output of the first command to the __stdin__ of the second.
410446
411447
<bonus-content>
412448
@@ -418,9 +454,8 @@ Use bash to customize your prompt.
418454
Explore options for what information would be most useful to you.
419455
Play around with fun colors and special symbols.
420456
421-
_**Hint**: to modify your prompt set a value to the `PS1` special variable._
457+
*__Hint__: to modify your prompt set a value to the `PS1` special variable.*
422458
423459
</home-work>
424460
425461
</bonus-content>
426-
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 'Working with branches'
3+
description: 'Most projects have a complicated history that is not a straight line'
4+
order: 4
5+
tags: ['git']
6+
# resources: {
7+
# }
8+
---
9+
10+
## Short recap
11+
12+
- Repositories are databases for content versions
13+
14+
- Commits are snapshots of the content of a repository
15+
16+
- Changes must first be added to the staging area before going into a commit
17+
18+
---

src/content/lessons/intro-to-git.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ title: 'Intro to git'
33
description: 'An overview of what git is, how it works and why we want to learn to use it'
44
order: 3
55
tags: ['intro', 'git']
6+
resources: {
7+
'Git docs': 'https://git-scm.com/docs',
8+
'Git book': 'https://git-scm.com/book/en/v2',
9+
'Intro to git by Scott Shacon': 'https://www.youtube.com/watch?v=ZDR433b0HJY',
10+
'Meaningful commit messages': 'https://www.conventionalcommits.org/en/v1.0.0/',
11+
}
612
---
713

8-
## Git
14+
## What is Git?
915

1016
Git is the most popular **version control system** in the world.
1117

src/content/lessons/more-bash.md

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: 'More bash'
3-
description: 'Diving deeper into bash features - test, pipes'
2+
title: 'Scripting with bash'
3+
description: 'Diving deeper into bash features, writing scripts'
44
order: 7
55
draft: true
66
tags: ['bash', 'unix']
@@ -16,50 +16,6 @@ declare -F # List all function names
1616

1717
---
1818

19-
## Command parsing order
20-
21-
Bash processes commands in this order:
22-
23-
1. History expansion (if enabled)
24-
2. Quote removal and word splitting
25-
3. Expansions (brace, tilde, parameter, arithmetic, command substitution, pathname)
26-
4. Redirection setup
27-
5. Command execution
28-
2919
---
3020

3121
> __Did you know:__ there is a version of the popular containerization tool Docker [written entirely in bash](https://github.com/p8952/bocker)
32-
33-
<bonus-content>
34-
35-
## Overview of the common top-level directories
36-
37-
> In UNIX-like system everything is represented as a file
38-
39-
```bash
40-
/ # root - the top level directory
41-
/bin/ # holds common programs accessible by all users
42-
/boot/ # contains files needed to start the system
43-
/dev/ # contains device files
44-
/etc/ # contains system configuration files
45-
/home/ # each user has their own directory under /home/{user-name}
46-
/media/ # usually where external storage is mounted
47-
/mnt/ # used for manually mounting external storage
48-
/lib/ # contains shared libraries
49-
```
50-
51-
---
52-
53-
```bash
54-
/opt/ # usually holds programs built locally from source
55-
/root/ # the home directory of the root user
56-
/sbin/ # contains programs only accessible to the root user
57-
/sys/ # contains files representing devices
58-
/tmp/ # contains temporary files
59-
/usr/ # holds a mish-mash of programs, libraries, docs and more
60-
/var/ # usually contains logs and other semi-temporary data
61-
```
62-
63-
> There are a lot of details and specifics of different UNIX variants that we would not have time to explore in depth.
64-
65-
</bonus-content>

src/content/lessons/the-terminal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ It handles things like displaying characters, managing window resizing, scrollin
2424
---
2525

2626
Popular modern terminal emulators include:
27+
2728
- Alacritty
2829
- Ghostty
2930
- Kitty
@@ -52,6 +53,7 @@ It handles things like parsing commands, managing environment variables, running
5253
---
5354

5455
Popular shells include:
56+
5557
- sh
5658
- bash
5759
- zsh
@@ -93,6 +95,7 @@ The **Portable Operating System Interface** is a standard specified by the IEEE
9395
---
9496

9597
It encompasses a large number of tools, programs and operating systems behaviours such as:
98+
9699
- Process creation and control
97100
- File system operations
98101
- Signals
@@ -111,6 +114,7 @@ It aims to be POSIX-compliant, but extends tools with multiple additional featur
111114
---
112115

113116
There are also multiple other implementations of the common Unix toolset such as:
117+
114118
- Plan9
115119
- BSD
116120
- BusyBox
@@ -128,6 +132,7 @@ Each of these implementations comes with its owns specifics, features and quirks
128132
<pop-quiz data-answer-id="1">
129133

130134
### The terminal is responsible for executing commands?
135+
131136
- true
132137
- false
133138

src/content/lessons/working-with-the-file-system.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ tail -n5 my-file.txt
195195
Use `grep` to find specific text within files:
196196

197197
```bash
198-
# find all markdown headings in a readme file
198+
# find all markdown headings in a markdown file
199199
cat readme.md | grep '#'
200200

201201
# can also be used directly, the first argument
@@ -234,6 +234,13 @@ mv a.txt b.md readmes/ ../docs/
234234
# copy files and directories
235235
cp .env config/ ../other-project/
236236

237+
# deletes the file from disk
238+
rm filename
239+
```
240+
241+
---
242+
243+
```bash
237244
# r = recursive, f = force
238245
# delete the directory with all files inside
239246
rm -rf useless-dir/

0 commit comments

Comments
 (0)