diff --git a/FS23_bash/README.md b/FS23_bash/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/FS23_bash/bib.bib b/FS23_bash/bib.bib new file mode 100644 index 0000000000000000000000000000000000000000..9a77fa200e9b235a872aacd4c60ac37c261912bd --- /dev/null +++ b/FS23_bash/bib.bib @@ -0,0 +1,2 @@ +% Encoding: UTF-8 + diff --git a/FS23_bash/cleanup.sh b/FS23_bash/cleanup.sh new file mode 100755 index 0000000000000000000000000000000000000000..83753619b66bac5a882fb3f2bbae6fd8a68bad4e --- /dev/null +++ b/FS23_bash/cleanup.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +rm -rf *.aux *.bbl *.blg *.fdb_latexmk *.fls *.log _minted-slides *.nav *.out *.pgf pythontex-files-* *.pytxcode *.snm *.toc *.vrb diff --git a/FS23_bash/code.sty b/FS23_bash/code.sty new file mode 100644 index 0000000000000000000000000000000000000000..d58bd7e80debfbb01d46483543cf69169f5ad5ba --- /dev/null +++ b/FS23_bash/code.sty @@ -0,0 +1,77 @@ +\ProvidesPackage{code} + +\usepackage{tcolorbox} +\usepackage{url} + + +\usepackage{tikz} +\usetikzlibrary{tikzmark,calc,,arrows,shapes,decorations.pathreplacing} +\tikzset{every picture/.style={remember picture}} + +\tcbuselibrary{skins,xparse,listings} + +% Props to https://tex.stackexchange.com/questions/517976/drawing-realistic-linux-command-shell-windows-with-tcolorbox + +\tcbset{common/.style={ + colback=violet!50!black, + colupper=white, + colframe=gray!65!black, + listing only, + listing options={ + style=tcblatex, + language=sh,escapeinside=``, + }, + every listing line={\MyMainPrompt}, +}} + +\newtcblisting{shell}[1][]{ + common, + title={\textcolor{orange}{\Large{$\bullet$}}{\textcolor{gray}{\Large{$\bullet\bullet$}}}}, + codewidth, + fontsize, + #1 +} + +\newtcblisting{shellcomp}[1][]{ + common, + codewidth, + fontsize, + #1 +} + +\tcbset{ + codewidth/.style={width=#1\textwidth}, + codewidth/.default=1, + fontsize/.style={% + listing options={ % TODO add only relevant stuff here (do not overwrite unrelated default) + style=tcblatex, + language=sh,escapeinside=``, + basicstyle=\ttfamily#1, + }, + }, + % fontsize/.default=\normalsize, +} + +% \BeforeBeginEnvironment{shell}{\centering} + +\pgfkeys{/shell/.cd, + user/.code={\gdef\MyMainUser{#1}}, + user={}, + host/.code={\gdef\MyMainHost{#1}}, + host={}, + color/.code={\gdef\MyMainColor{#1}}, + color=white, + pwd/.code={\gdef\MyMainPwd{#1}}, + pwd=\~, + prompt char/.code={\gdef\MyMainPromptChar{#1}}, + prompt char=\#, + root/.style={user=root,host=ubuntu,color=lime,pwd=/,prompt char=\#}, + alex/.style={user=alex,host=thealt,color=cyan,pwd=\~,prompt char=\$}, + bobremote/.style={user=bob,host=myRemote,color=green,pwd=\~,prompt char=>}, + alice/.style={user=alice,host=arch,color=green,pwd=\~,prompt char=>}, +} +\newcommand{\SU}[1]{ + \pgfkeys{/shell/.cd,#1}% + \gdef\MyMainPrompt{\textcolor{\MyMainColor}{\MyMainUser @\MyMainHost{\textcolor{white}:}\textcolor{cyan!60}{\url{\MyMainPwd}}{\textcolor{white}\MyMainPromptChar} }} +} +\newcommand{\StartConsole}{\gdef\MyMainPrompt{}} diff --git a/FS23_bash/compile.sh b/FS23_bash/compile.sh new file mode 100755 index 0000000000000000000000000000000000000000..0d531d01ac2e9f7ff1f6e90f3a1dc8d72dc32493 --- /dev/null +++ b/FS23_bash/compile.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +lualatex slides.tex +bibtex slides +lualatex slides.tex +lualatex slides.tex diff --git a/FS23_bash/header.tex b/FS23_bash/header.tex new file mode 100644 index 0000000000000000000000000000000000000000..fca7184b0ae4ce2dd9b11245288eda37773a35b0 --- /dev/null +++ b/FS23_bash/header.tex @@ -0,0 +1,84 @@ +\documentclass[aspectratio=169]{beamer} +\usepackage[T1]{fontenc} % the pipe character doesn't display properly without this +\usepackage{listings} +\usepackage{color} +\usepackage{datapie} +\usepackage{multicol} +\usepackage{upgreek} +\usepackage{siunitx} % pretty measurement unit rendering +\usepackage{hyperref} % enable hyperlink for URLs +\usepackage{lmodern} +\usepackage{setspace} +\usepackage[os=win]{menukeys} % by default keys are given for MacOS +\usepackage{xcolor} +\usepackage{subcaption} +\usepackage[style=norwegian]{csquotes} + +\usepackage{code} + +\usefonttheme[onlymath]{serif} +\setcounter{MaxMatrixCols}{20} + +\DeclareSIUnit\pixel{px} + +\usecolortheme[RGB={37,68,113}]{structure} +\usetheme{Dresden} + +\newenvironment{figurehere} +{\def\@captype{figure}} +{} +\makeatother + +\renewcommand{\arraystretch}{1.5} + +%Define generic colors +\definecolor{slg}{gray}{0.25} +\definecolor{lg}{gray}{0.53} +\definecolor{vlg}{gray}{0.73} +\definecolor{tlg}{gray}{0.91} + +%Define data colors +\definecolor{mygreen}{rgb}{0,0.6,0} +\definecolor{mygray}{rgb}{0.5,0.5,0.5} +\definecolor{mymauve}{rgb}{0.58,0,0.82} + +%Define TheAlt colors +\definecolor{ldorange}{HTML}{F18A20} +\definecolor{ldblue}{HTML}{254471} + +%Apply TheAlt colors to theme +\setbeamercolor{section in head/foot}{fg=ldorange} +\setbeamercolor{author in head/foot}{fg=white} +\setbeamercolor{subsection in head/foot}{fg=white} +\setbeamercolor{caption name}{fg=vlg} +\setbeamercolor{caption}{fg=vlg} +\setbeamercolor{frametitle}{fg=ldblue} +\setbeamercolor{title}{fg=ldorange} +\setbeamercolor{institute}{fg=ldblue} + +\setbeamerfont{title}{series=\bfseries} + +\setbeamertemplate{caption}{\raggedright\insertcaption\par} +\setbeamertemplate{navigation symbols}{} +\setbeamertemplate{bibliography item}[text] + +\lstdefinestyle{customc}{ + belowcaptionskip=1\baselineskip, + captionpos=, + breaklines=true, + frame=L, + xleftmargin=\parindent, + language=C, + showstringspaces=false, + basicstyle=\scriptsize\ttfamily, + rulecolor=\color{tlg}, + backgroundcolor=\color{tlg}, + fillcolor=\color{tlg}, + rulesepcolor=\color{tlg}, + keywordstyle=\bfseries\color{green!40!black}, + commentstyle=\itshape\color{purple!40!black}, + identifierstyle=\color{blue}, + stringstyle=\color{orange}, +} + +\lstset{language=C,caption={Descriptive Caption Text},label=DescriptiveLabel} diff --git a/FS23_bash/slides.listing b/FS23_bash/slides.listing new file mode 100644 index 0000000000000000000000000000000000000000..b95f111cb0a2913073ac7793926b26f83aa7d001 --- /dev/null +++ b/FS23_bash/slides.listing @@ -0,0 +1,3 @@ +./script.sh `\StartConsole` +Hello Everyone! + diff --git a/FS23_bash/slides.pdf b/FS23_bash/slides.pdf new file mode 100644 index 0000000000000000000000000000000000000000..38d1630a4ee076971ab0b48eb4154dd6c463ac69 Binary files /dev/null and b/FS23_bash/slides.pdf differ diff --git a/FS23_bash/slides.tex b/FS23_bash/slides.tex new file mode 100755 index 0000000000000000000000000000000000000000..7e62bd98e1df30e45bbf06fd801314a7c8c02620 --- /dev/null +++ b/FS23_bash/slides.tex @@ -0,0 +1,300 @@ +\input{header} + +\title{Bash} +\author{Nicolas König, Alexander Schoch} +\institute{TheAlternative | ETHZ and UZH} + +\date{Version: \today} + +\begin{document} + \begin{frame} + \titlepage + \end{frame} + + \begin{frame} + Contents + \tableofcontents + \end{frame} + + \section{Introduction} + + \begin{frame}{What is bash?} + \begin{itemize} + \item Shell: A program that exposes operating system services to the user + \item asdf + \end{itemize} + \end{frame} + + \begin{frame}{When to use bash?} + \begin{itemize} + \item Shell: A program that exposes operating system services to the user + \item asdf + \end{itemize} + \end{frame} + + % Why bash? + % What can you do with bash? + % Really easy + % Fast to write + + \section[CT Recap]{Console Toolkit Recap} + \subsection{Commands} + + \begin{frame}{Console Toolkit Recap\footnote[frame]{\href{https://gitlab.ethz.ch/thealternative/courses/-/blob/master/HS22\_ConsoleToolkit/main.pdf}{https://gitlab.ethz.ch/thealternative/courses/-/blob/master/HS22\_ConsoleToolkit/main.pdf}}} + + \begin{block}{Many (small) programs to do one thing well} + \begin{itemize} + \item \texttt{cd}: Change Directory + \item \texttt{pwd}: Present Working Directory + \item \texttt{ls}: List directory contents + \item \texttt{echo}: Print text + \item \texttt{cat}: Print file contents + \item \texttt{cp}: Copy + \item \texttt{mv}: Move / rename + \item \texttt{rm}: Remove + \end{itemize} + \end{block} + + \end{frame} + + \begin{frame}[fragile]{\texttt{cd}: Change Directory / \texttt{pwd}: Present Working Directory} + \SU{alex} + \begin{shell} +pwd `\StartConsole` +/home/alex `\SU{}` +cd Documents `\StartConsole\SU{}` +pwd `\StartConsole` +/home/alex/Documents `\SU{}` +cd .. `\StartConsole\SU{}` +pwd `\StartConsole` +/home/alex + \end{shell} + \end{frame} + + \begin{frame}[fragile]{\texttt{ls}: List directory contents} + \SU{alex} + \begin{shell} +ls `\StartConsole` +Desktop Downloads Pictures Templates +Documents Music Public Videos `\SU{}` +ls Documents `\StartConsole` +bash_guide.pdf `\SU{}` +ls -a Documents `\StartConsole` +. .. .secret_file bash_guide.pdf + \end{shell} + \end{frame} + + \begin{frame}[fragile]{\texttt{cat}: Concatenate file} + \SU{alex} + \begin{shell} +cat Documents/.secret_file `\StartConsole` +This is secret content. +You should not be reading this. + \end{shell} + \end{frame} + + \begin{frame}[fragile]{\texttt{echo}: Print text to stdout} + \SU{alex} + \begin{shell} +echo "Hello Everyone" `\StartConsole` +Hello Everyone `\SU{}` +echo "file.txt" `\StartConsole` +file.txt `\SU{}` +VARIABLE='Hello Everyone' `\StartConsole\SU{}` +echo "$VARIABLE" `\StartConsole` +Hello Everyone + \end{shell} + \end{frame} + + \begin{frame}[fragile]{\texttt{mkdir}: Make Directory} + \SU{alex} + \begin{shell} +ls `\StartConsole` +file `\SU{}` +mkdir some_folder `\StartConsole\SU{}` +ls `\StartConsole` +file some_folder + \end{shell} + \end{frame} + + + \begin{frame}[fragile]{\texttt{cp}: Copy} + \scriptsize + \SU{alex} + \begin{shell} +ls `\StartConsole` +file some_folder `\SU{}` +cp file some_folder `\StartConsole\SU{}` +ls `\StartConsole` +file some_folder `\SU{}` +ls some_folder `\StartConsole` +file `\SU{}` +cp file copy_of_file `\StartConsole\SU{}` +ls `\StartConsole` +copy_of_file file some_folder `\SU{}` +cp some_folder ~/Downloads `\StartConsole` +cp: -r not specified; omitting directory 'some_folder' `\SU{}` +cp -r some_folder ~/Downloads `\StartConsole` + \end{shell} + \end{frame} + + + + \begin{frame}[fragile]{\texttt{mv}: Move} + \SU{alex} + \begin{shell} +ls `\StartConsole` +file folder `\SU{}` +mv file file_with_new_name `\StartConsole\SU{}` +ls `\StartConsole` +file_with_new_name folder `\SU{}` +mv file_with_new_name folder/another_name `\StartConsole\SU{}` +ls folder `\StartConsole` +another_name + \end{shell} + \end{frame} + + \begin{frame}[fragile]{\texttt{rm}: Remove} + \scriptsize + \SU{alex} + \begin{shell} +ls `\StartConsole` +file some_folder `\SU{}` +rm file `\StartConsole\SU{}` +ls `\StartConsole` +some_folder `\SU{}` +rm some_folder `\StartConsole` +rm: cannot remove 'some_folder': Is a directory `\SU{}` +rmdir some_folder `\StartConsole` +rmdir: failed to remove 'some_folder': Directory not empty `\SU{}` +rm -r some_folder `\StartConsole\SU{}` +ls `\StartConsole\SU{}` +`\StartConsole` + \end{shell} + \end{frame} + + \begin{frame}[fragile]{\texttt{head}: Output first lines of file} + \scriptsize + \SU{alex} + \begin{shell} +cat numbers.txt `\StartConsole` +one +two +three +[...] +ten `\SU{}` +head -3 numbers.txt `\StartConsole` +one +two +three + \end{shell} + \normalsize + \textcolor{ldorange}{Note}\quad\texttt{tail} also exists! + \end{frame} + + \begin{frame}[fragile]{\texttt{grep}: \enquote{globally search for regex and print}} + \scriptsize + \SU{alex} + \begin{shell} +cat numbers.txt `\StartConsole` +one +two +three +[...] +ten `\SU{}` +grep 'ne' numbers.txt `\StartConsole` +one +nine `\SU{}` +grep -v 'e' numbers.txt `\StartConsole` +two +four +six + \end{shell} + \end{frame} + + \subsection{Piping \& Redirection} + + \begin{frame}[fragile]{Piping} + Use the output of one command as the input of another. Very useful! + \scriptsize + \SU{alex} + \begin{shell} +grep 'e' numbers.txt | sort `\StartConsole` +eight +five +nine +one +seven +ten +three + \end{shell} + \end{frame} + +% \begin{frame}[fragile]{Redirection} +% Redirect stdout into file +% \scriptsize +% \SU{alex} +% \begin{shell} +%cat file.txt `\StartConsole` +%Some Text `\SU{}` +%echo "Some more Text" >> file.txt `\StartConsole\SU{}` +%cat file.txt `\StartConsole` +%Some Text +%Some more Text `\SU{}` +%echo "Even more Text" > file.txt `\StartConsole\SU` +%cat file.txt `\StartConsole` +%Even more Text +% \end{shell} +% \end{frame} + + \begin{frame}[fragile]{Redirection} + Redirect stdout into file + \scriptsize + \SU{alex} + \begin{shell} +cat file.txt `\StartConsole` +Some Text `\SU{}` +echo "Some more Text" >> file.txt `\StartConsole\SU{}` +cat file.txt `\StartConsole` +Some Text +Some more Text `\SU{}` +echo "Even more Text" > file.txt `\StartConsole\SU{}` +cat file.txt `\StartConsole` +Even more Text + \end{shell} + \end{frame} + + \section{Scripting} + +% \begin{frame}[fragile]{Our first Script} +% \begin{shell} +%#!/bin/bash +% +%echo "Hello Everyone!" +% \end{shell} +% +% \textcolor{ldorange}{Note}\quad Make executable with \texttt{chmod +x script.sh} +% \end{frame} + + \begin{frame}[fragile]{Our first Script} + \scriptsize + \begin{shell} +\\#!/bin/bash + +echo "Hello Everyone!" + \end{shell} + \normalsize + \begin{itemize} + \item Make executable with \texttt{chmod +x script.sh} + \item Run with \texttt{./script.sh} + \end{itemize} + \scriptsize + \SU{alex} + \begin{shell} +./script.sh `\StartConsole` +Hello Everyone! + \end{shell} + \end{frame} + + +\end{document} diff --git a/FS23_bash/slides.vrb b/FS23_bash/slides.vrb new file mode 100644 index 0000000000000000000000000000000000000000..49e3a20811b8c88e9ac49c278accb87e456e6f1d --- /dev/null +++ b/FS23_bash/slides.vrb @@ -0,0 +1,18 @@ +\frametitle{Our first Script} +\scriptsize + \begin{shell} +\\#!/bin/bash + +echo "Hello Everyone!" + \end{shell} + \normalsize + \begin{itemize} + \item Make executable with \texttt{chmod +x script.sh} + \item Run with \texttt{./script.sh} + \end{itemize} + \scriptsize + \SU{alex} + \begin{shell} +./script.sh `\StartConsole` +Hello Everyone! + \end{shell}