From 51dbe77dee4e7f1a02b3f07a48d359d66f3a87ed Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Fri, 16 Jun 2023 00:28:08 +0200 Subject: [PATCH 1/3] add shell slides --- slides/shells/shells.md | 109 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 slides/shells/shells.md diff --git a/slides/shells/shells.md b/slides/shells/shells.md new file mode 100644 index 0000000..0ceeee2 --- /dev/null +++ b/slides/shells/shells.md @@ -0,0 +1,109 @@ +# Origin + +- Used as a 'shell' around a bare-ass kernel. +- People once considered a basic shell user-friendly. + +## Use Cases + +- It's crazy-fast +- Try deleting a file in Python. + +## Form + +- Big mess of binaries, wrapped together +- Janky mess + +# Bangs! + +Don't say `#!/bin/bash` if you don't mean it! + +| Bang! | Apraisal | +|:---------------|:--------------| +| `#!/bin/bash` | reasonable | +| `#!/bin/sh` | sensible | +| `#!/bin/dash` | bad idea | +| `#!/bin/zsh` | risky | +| `#!/bin/ksh` | foolish | +| `#!/bin/fish` | madness | +| `#!/bin/elvish`| genius | + +Protip: for a faster machine, make `sh` a link to `/bin/dash`. + +`ln -s /bin/dash /bin/dash` + +# Deviant Shells + +## `ksh` (korn shell) + +- Can be posix compliant with effort. +- vi mode by default. + +## `elvish` + +- pure style +- built-in browser +- Ctrl+i to search for commands in $PATH +- Ctrl+n to search for command arguments +- Ctrl+l to return to previous locations + +## Bash Advantages + +- Equality check with "==". + * Dash cannot do `if [ $x == 3 ]; then echo y; fi` +- `$RANDOM` +- Dash cannot use `&>/dev/null` +- No history + +# Protips + +``` +"\C- ": shell-expand-line +"\C-x": glob-expand-word +``` + +- `set -o vi` +- Ctrl+d +- `type $whatevre` +- `.inputrc` + +# Fun with Bash + +- wifi_qr.sh +- clean.sh +- theme.sh + +# Zen Master Foo + +Master Foo once said to a visiting programmer: "There is more Unix-nature in one line of shell script than there is in ten thousand lines of C." + +The programmer, who was very proud of his mastery of C, said: "How can this be? +C is the language in which the very kernel of Unix is implemented!" + +Master Foo replied: "That is so. +Nevertheless, there is more Unix-nature in one line of shell script than there is in ten thousand lines of C." + +# + +The programmer grew distressed. "But through the C language we experience the enlightenment of the Patriarch Ritchie! We become as one with the operating system and the machine, reaping matchless performance!" + +Master Foo replied: "All that you say is true. +But there is still more Unix-nature in one line of shell script than there is in ten thousand lines of C." + +The programmer scoffed at Master Foo and rose to depart. +But Master Foo nodded to his student Nubi, who wrote a line of shell script on a nearby whiteboard, and said: "Master programmer, consider this pipeline. +Implemented in pure C, would it not span ten thousand lines?" + +# + +The programmer muttered through his beard, contemplating what Nubi had written. +Finally he agreed that it was so. + +"And how many hours would you require to implement and debug that C program?" asked Nubi. + +"Many," admitted the visiting programmer. "But only a fool would spend the time to do that when so many more worthy tasks await him." + +"And who better understands the Unix-nature?" Master Foo asked. "Is it he who writes the ten thousand lines, or he who, +perceiving the emptiness of the task, gains merit by not coding?" + +Upon hearing this, the programmer was enlightened. + From b60bd5d6313952c2f3372e286a67087dd61ce89c Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Fri, 16 Jun 2023 02:25:05 +0200 Subject: [PATCH 2/3] edit shells slides --- slides/shells/shells.md | 70 ++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/slides/shells/shells.md b/slides/shells/shells.md index 0ceeee2..3befb9d 100644 --- a/slides/shells/shells.md +++ b/slides/shells/shells.md @@ -2,30 +2,28 @@ - Used as a 'shell' around a bare-ass kernel. - People once considered a basic shell user-friendly. +- Once worked as slow printing. ## Use Cases -- It's crazy-fast +- It's crazy-fast to write. - Try deleting a file in Python. - -## Form - -- Big mess of binaries, wrapped together -- Janky mess +- It's awful for any structured data. # Bangs! Don't say `#!/bin/bash` if you don't mean it! -| Bang! | Apraisal | -|:---------------|:--------------| -| `#!/bin/bash` | reasonable | -| `#!/bin/sh` | sensible | -| `#!/bin/dash` | bad idea | -| `#!/bin/zsh` | risky | -| `#!/bin/ksh` | foolish | -| `#!/bin/fish` | madness | -| `#!/bin/elvish`| genius | +| Bang! | Apraisal | +|:------------------------|:--------------| +| `#!/bin/bash` | reasonable | +| `#!/bin/sh` | sensible | +| `#!/bin/dash` | bad idea | +| `#!/bin/zsh` | risky | +| `#!/bin/ksh` | foolish | +| `#!/usr/bin/env bash` | pathetic | +| `#!/bin/fish` | madness | +| `#!/bin/elvish` | genius | Protip: for a faster machine, make `sh` a link to `/bin/dash`. @@ -35,8 +33,9 @@ Protip: for a faster machine, make `sh` a link to `/bin/dash`. ## `ksh` (korn shell) -- Can be posix compliant with effort. -- vi mode by default. +- made before `bash` +- `vi` mode by default (means you're a hacker) +- Can be posix compliant with effort ## `elvish` @@ -46,13 +45,40 @@ Protip: for a faster machine, make `sh` a link to `/bin/dash`. - Ctrl+n to search for command arguments - Ctrl+l to return to previous locations -## Bash Advantages +## zsh + +- `for x in 1..10` + +# Bash Advantages - Equality check with "==". * Dash cannot do `if [ $x == 3 ]; then echo y; fi` - `$RANDOM` - Dash cannot use `&>/dev/null` - No history +- `$PROMPT_COMMAND` + +## Lists + +``` +myList+=(*) +echo "${myList[0]}" +``` + +# Functions + + +``` +function wotsa(){ + def="$(curl -s dict://dict.org/define:$1: | \ + grep -vP '^\d\d\d ')" + if [ "$def" = "" ]; then + echo no definition + else + echo "$def" | mdcat -p + fi +} +``` # Protips @@ -61,16 +87,22 @@ Protip: for a faster machine, make `sh` a link to `/bin/dash`. "\C-x": glob-expand-word ``` +- `set -e` +- `set -x` - `set -o vi` - Ctrl+d -- `type $whatevre` +- `type $whatever` - `.inputrc` +- `PS1=foo` # Fun with Bash - wifi_qr.sh - clean.sh - theme.sh +- notflix.sh +- clip.sh +- vidget.sh # Zen Master Foo From b1cee86b4c4bf02a6ada0f7f135b0291a370f97d Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Mon, 19 Jun 2023 18:38:44 +0200 Subject: [PATCH 3/3] add shell arguments --- slides/shells/shells.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/slides/shells/shells.md b/slides/shells/shells.md index 3befb9d..1bf02ce 100644 --- a/slides/shells/shells.md +++ b/slides/shells/shells.md @@ -48,6 +48,7 @@ Protip: for a faster machine, make `sh` a link to `/bin/dash`. ## zsh - `for x in 1..10` +- great autocompletion # Bash Advantages @@ -94,6 +95,8 @@ function wotsa(){ - `type $whatever` - `.inputrc` - `PS1=foo` +- `^$` for first argument used +- `!$` for last argument used # Fun with Bash