2024-11-29 09:02:47 +02:00
|
|
|
#+title: lesson 02 | course overview + the shell
|
|
|
|
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../_share/media/css/missing-semester.css" />
|
2024-12-01 00:48:05 +02:00
|
|
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../_share/media/css/org-media-sass/collapsible.css" />
|
2024-11-29 10:36:09 +02:00
|
|
|
#+HTML_HEAD: <script src="../_share/media/js/collapsible.js"></script>
|
2024-11-29 09:02:47 +02:00
|
|
|
|
|
|
|
|
* Links
|
|
|
|
|
#+attr_html: :class links
|
|
|
|
|
- [[../toc.org][TOC | Missing Semester]]
|
|
|
|
|
- [[https://www.youtube.com/playlist?list=PLyzOVJj3bHQuloKGG59rS43e29ro7I57J][Playlist: Missing Semester]]
|
|
|
|
|
|
2024-12-02 01:00:50 +02:00
|
|
|
*** timestamps
|
|
|
|
|
:PROPERTIES:
|
|
|
|
|
:CUSTOM_ID: timestamp
|
|
|
|
|
:END:
|
|
|
|
|
|
|
|
|
|
#+attr_html: :class playlist
|
2024-12-12 18:30:39 +02:00
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=54s][00:54 - control flow functions]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=227s][03:47 - sequential execution]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=425s][07:05 - standard input]] *current*
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=444s][07:24 - error code]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=517s][08:37 - logical operators]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=603s][10:03 - concatenate commands]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=645s][10:45 - common substitution]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=675s][11:15 - process substitution]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=935s][15:35 - comparison operator]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=1173s][19:33 - curly braces]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=1359s][22:39 - python script]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=1707s][28:27 - man command]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=2175s][36:15 - finding files]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=2190s][36:30 - grep]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=2573s][42:53 - fuzzy finder]]
|
|
|
|
|
+ [[https://www.youtube.com/watch?v=kgII-YWo3Zw&t=2649s][44:09 - history substring search]]
|
2024-12-02 01:00:50 +02:00
|
|
|
|
2024-11-29 09:02:47 +02:00
|
|
|
* Notes
|
|
|
|
|
|
2024-12-01 22:43:43 +02:00
|
|
|
** bash
|
|
|
|
|
*** spaces are critical with bash
|
|
|
|
|
- this works:
|
|
|
|
|
#+begin_src bash
|
|
|
|
|
foo=bar
|
|
|
|
|
echo $foo
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
- this doesn't:
|
|
|
|
|
#+begin_src bash
|
|
|
|
|
foo = bar
|
|
|
|
|
echo $foo
|
|
|
|
|
#+end_src
|
|
|
|
|
|
2024-12-12 18:30:39 +02:00
|
|
|
- the output of that will be
|
|
|
|
|
=zsh: command not found: foo=
|
2024-12-01 22:43:43 +02:00
|
|
|
|
2024-12-12 18:30:39 +02:00
|
|
|
- what happens in the above example is that we are effectively calling the "foo" program with the arguments: "=" and "bar"
|
2024-12-01 22:43:43 +02:00
|
|
|
|
|
|
|
|
*** quotes
|
|
|
|
|
- you can use double or single quotes to print a value
|
|
|
|
|
#+begin_src bash
|
|
|
|
|
echo "Hello"
|
|
|
|
|
#+end_src
|
|
|
|
|
#+begin_src bash
|
|
|
|
|
echo 'Hello'
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
- double quotes can interpolate variables
|
|
|
|
|
#+begin_src bash
|
|
|
|
|
echo "Value is $foo"
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
will return: =Value is bar=
|
|
|
|
|
|
|
|
|
|
- single quotes can NOT interpoloate variables
|
|
|
|
|
#+begin_src bash
|
|
|
|
|
echo 'Value is $foo'
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
will return: =Value is $foo=
|
2024-11-29 09:02:47 +02:00
|
|
|
|
2024-12-12 18:30:39 +02:00
|
|
|
** sequential execution
|
|
|
|
|
|
|
|
|
|
*** bash functions
|
|
|
|
|
- mcd.sh
|
|
|
|
|
#+begin_src bash
|
|
|
|
|
mcd() {
|
|
|
|
|
mkdir -p "$1"
|
|
|
|
|
cd "$1"
|
|
|
|
|
}
|
|
|
|
|
#+end_src bash
|
|
|
|
|
|
|
|
|
|
- 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
|
|
|
|
|
|
|
|
|
|
#+begin_src bash
|
|
|
|
|
ls -lah
|
|
|
|
|
sudo !!
|
|
|
|
|
#+end_src
|