5
This commit is contained in:
		
							
								
								
									
										125
									
								
								5.html
									
									
									
									
									
								
							
							
						
						
									
										125
									
								
								5.html
									
									
									
									
									
								
							@@ -47,15 +47,8 @@
 | 
			
		||||
 | 
			
		||||
					<aside class="notes">
 | 
			
		||||
						Frage: Fragen zur letzten Stunde?
 | 
			
		||||
					</aside>
 | 
			
		||||
				</section>
 | 
			
		||||
				
 | 
			
		||||
				<section>
 | 
			
		||||
					<h2>Bash scripting - Fortsetzung</h2>
 | 
			
		||||
				</section>
 | 
			
		||||
 | 
			
		||||
				<section>
 | 
			
		||||
					<h3>LINKS</h3>
 | 
			
		||||
						<h3>LINKS</h3>
 | 
			
		||||
 | 
			
		||||
					<p>http://tldp.org/LDP/abs/html/complexfunct.html
 | 
			
		||||
 | 
			
		||||
@@ -71,8 +64,13 @@
 | 
			
		||||
					- kontrollstrukturen
 | 
			
		||||
					- 
 | 
			
		||||
 | 
			
		||||
					</aside>
 | 
			
		||||
				</section>
 | 
			
		||||
				
 | 
			
		||||
				<section>
 | 
			
		||||
					<h2>Bash scripting - Fortsetzung</h2>
 | 
			
		||||
					<h3>Wiederholung</h3>
 | 
			
		||||
				</section>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
				<section>
 | 
			
		||||
					<h3>Variablen</h3>
 | 
			
		||||
@@ -133,8 +131,9 @@ message="hallo Welt"
 | 
			
		||||
message=hello\ Welt
 | 
			
		||||
					</code></pre>
 | 
			
		||||
				</section>
 | 
			
		||||
				<section><pre><code>echo 'So sprach'"'"'s und ging ohne einen Backslash (\) weiter.'
 | 
			
		||||
     └────┬────┘└┬┘└─────────────────────┬─────────────────────┘
 | 
			
		||||
				<section><pre style="font-size: .5em;width: auto"><code>
 | 
			
		||||
echo 'So sprach'"'"'s und ging ohne einen Backslash (\) weiter.'
 | 
			
		||||
     └───┬───┘└┬┘└──────────────────┬─────────────────────┘
 | 
			
		||||
          │      │                       │
 | 
			
		||||
          │      │                       └ Dritter Bereich: Wieder
 | 
			
		||||
          │      │                         von ' umschlossen, der 
 | 
			
		||||
@@ -213,9 +212,11 @@ tar cf archiv.tar && rm *.doc || echo "fehler"</code></pre>
 | 
			
		||||
			        <pre class="fragment"><code>#!/bin/bash
 | 
			
		||||
OUTFILE="liste.txt"
 | 
			
		||||
 | 
			
		||||
liste=`ls | tee $OUTFILE `
 | 
			
		||||
liste=`ls`
 | 
			
		||||
echo $liste > $OUTFILE
 | 
			
		||||
 | 
			
		||||
echo $liste
 | 
			
		||||
#mit tee in einer Zeile
 | 
			
		||||
liste=`ls | tee $OUTFILE`
 | 
			
		||||
 | 
			
		||||
cat $OUTFILE
 | 
			
		||||
 </code></pre>
 | 
			
		||||
@@ -244,12 +245,29 @@ count () {
 | 
			
		||||
 | 
			
		||||
  # ls: Liste aller Objekte im Verzeichnis
 | 
			
		||||
  # wc: Word-Count; mit Attribut -l werden Zeilen gezählt
 | 
			
		||||
  # in Verbindung mit ls werden also die (nicht versteckten) Objekte gezählt
 | 
			
		||||
  # in Verbindung mit ls werden also die 
 | 
			
		||||
  # (nicht versteckten) Objekte gezählt
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
count        # Aufruf der Funktion
 | 
			
		||||
		        	</code></pre>
 | 
			
		||||
		        </section>
 | 
			
		||||
		        <section>
 | 
			
		||||
		        	<pre><code>#!/bin/sh
 | 
			
		||||
 
 | 
			
		||||
fatal() {
 | 
			
		||||
     msg=$1
 | 
			
		||||
     echo "Fatal: $msg"
 | 
			
		||||
     exit 1
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
[ -d /tmp ] || fatal "Verzeichnis /tmp existiert nicht"
 | 
			
		||||
[ -w /tmp ] || fatal "Verzeichnis /tmp nicht schreibbar"
 | 
			
		||||
 
 | 
			
		||||
TMP=/tmp/mydir
 | 
			
		||||
[ -d $TMP ] || mkdir $TMP    # tmp-Verz. erzeugen, wenn noch nicht vorhanden
 | 
			
		||||
		        	</code></pre>
 | 
			
		||||
		        </section>
 | 
			
		||||
		        <section>
 | 
			
		||||
		        	<pre><code>#!/bin/bash
 | 
			
		||||
count2 () {
 | 
			
		||||
@@ -268,36 +286,51 @@ echo "Status: $?"
 | 
			
		||||
count2 "/etc"
 | 
			
		||||
echo "Status: $?"</code></pre>
 | 
			
		||||
		        </section>
 | 
			
		||||
		        <section>
 | 
			
		||||
		        	    <div class="fragment"><pre><code>#!/bin/bash
 | 
			
		||||
tar -czf myhome_directory.tar.gz /home/$USER
 | 
			
		||||
mkdir archiv
 | 
			
		||||
mv myhome_directory.tar.gz archiv/
 | 
			
		||||
 | 
			
		||||
						</code></pre>
 | 
			
		||||
					</div>
 | 
			
		||||
		        </section>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		        
 | 
			
		||||
		        <section style="font-size: .8em">
 | 
			
		||||
		        <span style="color: orange">Aufgabe:</span> Erstellt script mit mind einer Funktion das: 
 | 
			
		||||
			        <ul>
 | 
			
		||||
			        	<li>ein Backup eines Verzeichnisses erstellt</li>
 | 
			
		||||
			        	<li>per Parameter den namen des Quell-Verzeichnis erhält</li>
 | 
			
		||||
			        	<li>per Parameter den Namen der Zieldatei erhält</li>
 | 
			
		||||
			        	<li>einen nützlichen exit code setzt</li>
 | 
			
		||||
			        	<li>vielleicht nützliche Meldungen ausgibt</li>
 | 
			
		||||
			        </ul>
 | 
			
		||||
			        <div><p>Tipps:</p>
 | 
			
		||||
			        	<ul>
 | 
			
		||||
			        		<li>Parameter Übergabe: kommando param1 param2</li>
 | 
			
		||||
			        		<li>Parameter Übernahme: param1 = $1 , param2 = $2 etc</li>
 | 
			
		||||
			        	</ul>
 | 
			
		||||
			        </div>
 | 
			
		||||
			        </section>
 | 
			
		||||
<section style="font-size: .8em">
 | 
			
		||||
			      <pre><code>#!/bin/bash
 | 
			
		||||
function file_backup {
 | 
			
		||||
	echo 'Backup --- building tar File...'
 | 
			
		||||
	tar -czf $2 $1 || fail "Fehler beim Archiv erstellen"
 | 
			
		||||
	echo '+DONE'
 | 
			
		||||
 | 
			
		||||
	exit 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fail () {
 | 
			
		||||
	echo "Fehler! + $1"
 | 
			
		||||
	exit 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#function call
 | 
			
		||||
# file_backup 'backup-quelle' 'backup-ziel.tar.gz'
 | 
			
		||||
file_backup $1 $2
 | 
			
		||||
 | 
			
		||||
					</code></pre>
 | 
			
		||||
					<aside class="notes">
 | 
			
		||||
						hinzufügen überprüfung ob quelle verz. <br>
 | 
			
		||||
						überprüfung ob ziel existiert <br>
 | 
			
		||||
						überpr. ob ziel angelegt <br>
 | 
			
		||||
						überprüf ob param vorhanden <br>
 | 
			
		||||
						backup verz anlegen
 | 
			
		||||
					</aside>
 | 
			
		||||
 				</section>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
				<section>
 | 
			
		||||
@@ -313,11 +346,10 @@ let "m++"
 | 
			
		||||
let "m--"
 | 
			
		||||
</code></pre>
 | 
			
		||||
 | 
			
		||||
let "k = (m < 9) ? 0 : 1"
 | 
			
		||||
condition ? value-if-true : value-if-false
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
          <pre><code>
 | 
			
		||||
Floating Poin:
 | 
			
		||||
Floating Point:
 | 
			
		||||
echo "32.0 + 1.4" | bc 
 | 
			
		||||
 | 
			
		||||
echo `expr $m + 18`
 | 
			
		||||
@@ -326,8 +358,13 @@ m=`expr $m + 18`
 | 
			
		||||
(( m *= 4 ))
 | 
			
		||||
</code></pre>
 | 
			
		||||
				</section>
 | 
			
		||||
				<section>ternary operator
 | 
			
		||||
					<pre><code>let "k = (m < 9) ? 0 : 1"
 | 
			
		||||
condition ? value-if-true : value-if-false</code></pre></section>
 | 
			
		||||
				<section data-transition="slide" data-background="#4d7e65" data-background-transition="zoom">
 | 
			
		||||
       
 | 
			
		||||
					<h3>Maus ist voll 90er !!</h3>
 | 
			
		||||
       		<a href="https://github.com/agarrharr/awesome-cli-apps">https://github.com/agarrharr/awesome-cli-apps</a>
 | 
			
		||||
       		<a href="https://github.com/alebcay/awesome-shell">https://github.com/alebcay/awesome-shell</a>
 | 
			
		||||
				</section>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user