This commit is contained in:
2019-01-04 10:41:14 +01:00
parent fa163ed552
commit 9e0ffb8193
10 changed files with 2589 additions and 19 deletions

172
4.html
View File

@@ -29,6 +29,10 @@
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<style type="text/css">
.reveal img{ max-height: 60vh}
</style>
</head>
@@ -196,6 +200,24 @@ USER Benutzername</code></pre>
</ul>
</section>
<section>
Damit ein Script wie ein Programm startet:
<ul>
<li class="fragment ">Pfad d. Skriptes der $PATH Variable hinzufügen</li>
<li class="fragment "><pre><code>export PATH=$PATH:/pfad/zum/script</code></pre></li>
<li class="fragment ">muss in die .bashrc</li>
<li class="fragment ">Best Practice: Scripte in Ordner <code>~/bin/</code> -> diesen zur <code>$PATH</code> dazu</li>
</ul>
<aside class="notes">
PATH nur in der aktuellen Sizung -> sonst in die .bashrc
</aside>
</section>
<section data-transition="slide" data-background="#4d7e65" data-background-transition="zoom">
<h2>Gentlemen, open your Editor! </h2>
</section>
<section style="font-size: .6em">
<pre><code>#!/bin/bash
@@ -218,8 +240,8 @@ uptime
MSG="\nDas ist alles! Bye, $USER! \n\n"
printf "${MSG}"</code></pre>
<small><a href="https://git.scytec.de/danthefan/linuxkurs/raw/master/beispiele/mysystem.sh" target="_blank">https://git.scytec.de/danthefan/linuxkurs/raw/master/beispiele/mysystem.sh</a></small>
<p><small><a href="https://www.schubertdaniel.de/linuxkurs" target="_blank">https://www.schubertdaniel.de/linuxkurs</a></small>
<p><small><a href="https://git.scytec.de/danthefan/linuxkurs/raw/master/beispiele/mysystem.sh" target="_blank">https://git.scytec.de/danthefan/linuxkurs/raw/master/beispiele/mysystem.sh</a></small>
</section>
<section>
@@ -280,20 +302,81 @@ dany 23893 4143 0 12:33 pts/4 00:00:00 bash
<p class="fragment "> Der <span class="fragment highlight-red">Kontext</span> aller Script Variablen ist der der <span class="fragment highlight-red">sub-shell</span>
</section>
<section>
Damit Script wie Programm startet:
<ul>
<li class="fragment ">Pfad d. Skriptes der $PATH Variable hinzufügen</li>
<li class="fragment "><pre><code>export PATH=$PATH:/pfad/zum/script</code></pre></li>
<li class="fragment ">muss in die .bashrc</li>
<li class="fragment ">Best Practice: Scripte in Ordner <code>~/bin/</code> -> diesen zur <code>$PATH</code> dazu</li>
</ul>
<aside class="notes">
PATH nur in der aktuellen Sizung -> sonst in die .bashrc
</aside>
<section>
<div><span style="color: orange">Aufgabe:</span> Erstellt ein script, das alle Dateien in eurem home in einer tar.gz - Datei archiviert, das Verzeichnis "~/archiv" erstellt, und die tar.gz Datei dorthin verschiebt.<br />
Hinweis: tar -czf .....
<p class="fragment">https://linuxconfig.org/bash-scripting-tutorial</p></div>
<dir class="fragment"><pre><code>#!/bin/bash
tar -czf myhome_directory.tar.gz /home/$USER
mkdir archiv
mv myhome_directory.tar.gz archiv/
</code></pre></dir>
</section>
<section>
<h3>Kontrollstrukturen</h3>
</section>
<section>
<h4>if then </h4>
<img src="img/if_then_else.svg">
</section>
<section><pre><code>#!/bin/bash
cd
ls
if [ -e sample.sh ]
then
echo "file exists!"
else
echo "file does not exist"
fi</code></pre></section>
<section>
<h4>if then elif</h4>
<img src="img/2_if_then_elif_fi.svg">
</section>
<section><pre style="font-size: .35em"><code>#!/bin/bash
cd
ls -l
read -p "Enter a file name: " filename
if [ -e $filename ]
then
echo "file exists!"
if [ -r $filename ]
then
status="readable "
fi
if [ -w $filename ]
then
status=$status"writable "
fi
if [ -x $filename ]
then
status=$status"executable"
fi
echo "file permission: "$status
else
echo "file does not exist"
fi</code></pre></section>
<section>
<h4>for loop</h4>
<img src="img/for.svg">
</section>
<section><pre><code>#!/bin/bash
for f in {1..9}
do
touch "$f xx.txt"
done</code></pre></section>
<section>
Ein weiteres Beispiel:
<pre><code>#!/bin/bash
@@ -312,15 +395,66 @@ if [ $# -gt 0 ]
echo "Beende ...."
fi
</code></pre>
<aside class="notes">beispiele/create_files_with_spaces.sh</aside>
</section>
<section>
<p>Kommando Verkettung</p>
<ul>
<li class="fragment ">this</li>
</ul>
<h4>case</h4>
<img src="img/3_case_var.jpg">
</section>
<section><pre style="font-size: .35em"><code>#!/bin/bash
clear
read -p "Integer1: " int1
read -p "Integer2: " int2
printf "Menu: \n[a] Addition\n[b]Subtraction\n[c]Multiplication\n[d]Division\n"
echo "======================"
read -p "Your choice: " choice
res=0
case $choice in
a)
res=$((int1+int2))
;;
b)
res=$((int1-int2))
;;
c)
res=$((int1*int2))
;;
d)
res=$((int1/int2))
;;
*)
echo "Invalid input"
esac
echo "The result is: " $res</code></pre></section>
<section>
<h4>while loop</h4>
<img src="img/4_while.svg">
</section>
<section><pre><code>#!/bin/bash
x=1
while [ $x -le 5 ]
do
echo "Welcome $x times"
x=$(( $x + 1 ))
done</code></pre></section>
<section>
<h4>until loop</h4>
<img src="img/until.svg">
</section>
<section><pre><code>#!/bin/bash
i=1
until [ $i -gt 6 ]
do
echo "Welcome $i times."
i=$(( i+1 ))
done</code></pre></section>
<section><h3>while vs until</h3>
<ol>
<li>until läuft bis Bedingung nicht 0 (false)</li>
<li>while läuft bis Bedingung 0 (true)</li>
<li>until läuft mind. einmal</li>
</ol>
</section>
</div>
</div>