3.6 KiB
3.6 KiB
lesson 02 | course overview + the shell
Links
timestamps
- 00:54 - control flow functions
- 03:47 - sequential execution
- 07:05 - standard input current
- 07:24 - error code
- 08:37 - logical operators
- 10:03 - concatenate commands
- 10:45 - common substitution
- 11:15 - process substitution
- 15:35 - comparison operator
- 19:33 - curly braces
- 22:39 - python script
- 28:27 - man command
- 36:15 - finding files
- 36:30 - grep
- 42:53 - fuzzy finder
- 44:09 - history substring search
Notes
bash
spaces are critical with bash
- this works:
foo=bar
echo $foo
- this doesn't:
foo = bar
echo $foo
- the output of that will be
zsh: command not found: foo - what happens in the above example is that we are effectively calling the "foo" program with the arguments: "=" and "bar"
quotes
-
you can use double or single quotes to print a value
echo "Hello"echo 'Hello' -
double quotes can interpolate variables
echo "Value is $foo"will return:
Value is bar -
single quotes can NOT interpoloate variables
echo 'Value is $foo'will return:
Value is $foo
sequential execution
bash functions
- mcd.sh
mcd() {
mkdir -p "$1"
cd "$1"
}
-
creates a function that can be executed after loading
- $1 is a global variable referring to the first parameter
source
- using source mcd.sh
source mcd.sh - then carry out the function
mcd testdir - this will create a new directory and cd into it as per the definied functioned
variables
-
$0 – name of the script we are currently in
- if you run this in the shell it will display 'bash'
- $1->$9 – the first through ninth argument given to a script
- $? – the last error message
- $_ — last argument of the previous call
-
!! – recreates the last call with it's arguments
- use with sudo if you found your call needed a sudo and you don't feel like retyping it again
ls -lah sudo !!