Skip to content
Snippets Groups Projects
Commit 086e709e authored by Alexander Schoch's avatar Alexander Schoch
Browse files

start bash course

parent bac7a9f3
No related branches found
No related tags found
No related merge requests found
% Encoding: UTF-8
#!/usr/bin/env bash
rm -rf *.aux *.bbl *.blg *.fdb_latexmk *.fls *.log _minted-slides *.nav *.out *.pgf pythontex-files-* *.pytxcode *.snm *.toc *.vrb
\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{}}
#!/usr/bin/env bash
lualatex slides.tex
bibtex slides
lualatex slides.tex
lualatex slides.tex
\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}
./script.sh `\StartConsole`
Hello Everyone!
File added
\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}
\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}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment