This commit is contained in:
Daniel Schubert 2019-01-10 12:09:22 +01:00
parent 08a7d276c5
commit c15ef1bab5
9 changed files with 547 additions and 44 deletions

125
5.html
View File

@ -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>

0
beispiele/4/mysystem.sh Normal file → Executable file
View File

Binary file not shown.

0
beispiele/5/04-function-exitcode.sh Normal file → Executable file
View File

0
beispiele/5/07-select-menu.sh Normal file → Executable file
View File

0
beispiele/5/09-backup.sh Normal file → Executable file
View File

16
beispiele/5/aufgabe2.sh Executable file
View File

@ -0,0 +1,16 @@
#!/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 $1 $2

View File

@ -0,0 +1,2 @@
{
}

View File

@ -0,0 +1,448 @@
{
"auto_complete":
{
"selected_items":
[
[
"cod",
"code"
],
[
"data",
"database"
],
[
"file",
"filesize"
],
[
"json",
"json_encode"
],
[
"wp",
"wp_die"
],
[
"fu",
"function"
],
[
"deep",
"deep_copy_sheet"
],
[
"c",
"compact"
],
[
"R",
"RuleSet"
],
[
"clean",
"clean_sheet"
],
[
"s",
"save_clean_css"
],
[
"st",
"stylesheet_url"
],
[
"cle",
"clean_sheet"
],
[
"rule",
"rule_to_remove"
],
[
"sty",
"stylesheet"
],
[
"selector",
"selectors"
],
[
"sel",
"selectors"
],
[
"each",
"each_selector"
],
[
"col",
"collect_styled_tags"
],
[
"ava",
"available_elemnts"
],
[
"im",
"image"
],
[
"in",
"input"
],
[
"i",
"items"
],
[
"font",
"font-family\tproperty"
],
[
"con",
"console\tvar"
],
[
"set",
"setTimeout\tfunction"
],
[
"lo",
"log"
],
[
"new",
"newsletter\tparameter"
],
[
"nw",
"Newsletter\talias"
],
[
"nu",
"number\tkeyword"
]
]
},
"buffers":
[
{
"file": "5.html",
"settings":
{
"buffer_size": 10102,
"encoding": "UTF-8",
"line_ending": "Unix"
}
}
],
"build_system": "",
"build_system_choices":
[
],
"build_varint": "",
"command_palette":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"console":
{
"height": 158.0,
"history":
[
"ls"
]
},
"distraction_free":
{
"menu_visible": true,
"show_minimap": false,
"show_open_files": false,
"show_tabs": false,
"side_bar_visible": false,
"status_bar_visible": false
},
"file_history":
[
"/home/dany/projekte/linuxkurs/beispiele/jpg/rename-jpg.sh",
"/home/dany/ownCloud/skripte/pwgen.sh",
"/home/dany/ownCloud/skripte/txt/recursive-grep-in-file.sh",
"/home/dany/ownCloud/skripte/txt/rec-cp.sh",
"/home/dany/bin/i3-mulit-mon.py",
"/home/dany/projekte/linuxkurs/2.html",
"/home/dany/projekte/linux-kurs/slide/Gruntfile.js",
"/home/dany/projekte/rvv/wordpress/rvv-dkr/wp-content/plugins/vinyl-download/vinyl-downloader.php",
"/home/dany/projekte/rvv/wordpress/rvv-dkr/wp-content/themes/rvv-gitlab/sass/rvv.sass",
"/home/dany/projekte/rvv/wordpress/rvv-dkr/wp-content/themes/rvv-gitlab/template-digital-download.php",
"/home/dany/projekte/rvv/wordpress/rvv-dkr/wp-content/plugins/vinyl-download/includes/js/ajax.js",
"/home/dany/projekte/rvv/wordpress/rvv-dkr/Gruntfile.js",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/assets/semantic-ui/semantic.css",
"/home/dany/projekte/linux-kurs/slide/index.html",
"/home/dany/projekte/ruby-uncss/c.css",
"/home/dany/projekte/ruby-uncss/clean1.css",
"/home/dany/projekte/ruby-uncss/sel.txt",
"/home/dany/projekte/linux-kurs/ideen.txt",
"/home/dany/projekte/linux-kurs/reveal.js-master/css/reveal.scss",
"/home/dany/projekte/linux-kurs/reveal.js-master/aaa.html",
"/home/dany/projekte/ruby-uncss/test.html",
"/home/dany/projekte/ruby-uncss/test.rb",
"/home/dany/projekte/ruby-uncss/spectre-test.css",
"/home/dany/projekte/ruby-uncss/a.css",
"/home/dany/projekte/ruby-uncss/ruby-uncss-sass.rb",
"/home/dany/projekte/ruby-uncss/clean2.css",
"/home/dany/projekte/ruby-uncss/spectre.css",
"/home/dany/projekte/ruby-uncss/aa.txt",
"/home/dany/projekte/ruby-uncss/rulesets.css",
"/home/dany/projekte/ruby-uncss/skipped-styles.css",
"/home/dany/projekte/ruby-uncss/Gemfile",
"/home/dany/projekte/ruby-uncss/tags.txt",
"/home/dany/projekte/ruby-uncss/tags.rb",
"/home/dany/projekte/ruby-uncss/vendor/bundle/ruby/2.3.0/gems/css_parser-1.6.0/lib/css_parser/rule_set.rb",
"/home/dany/projekte/ruby-uncss/test.css",
"/home/dany/projekte/ruby-uncss/clean.css",
"/home/dany/projekte/ruby-uncss/html-parser.rb",
"/home/dany/.bash_aliases",
"/home/dany/.config/i3/config",
"/home/dany/tmp/html-parser.rb",
"/home/dany/projekte/acs/grav/user/pages/01.kunden/porsche/sitzung-mai-2018/single-project.de.md",
"/home/dany/projekte/acs/grav/user/themes/acs/templates/customer.html.twig",
"/home/dany/projekte/acs/grav/system/blueprints/config/site.yaml",
"/home/dany/projekte/acs/grav/user/pages/01.kunden/porsche/projekt-1/single-project.de.md",
"/home/dany/projekte/acs/grav/user/pages/01.kunden/porsche/projekt-2/single-project.de.md",
"/home/dany/.config/polybar/config",
"/home/dany/projekte/acs/grav/user/config/system.yaml",
"/home/dany/projekte/acs/grav/user/pages/01.kunden/porsche/customer.de.md",
"/home/dany/projekte/acs/grav/user/pages/01.kunden/mazda/customer.de.md",
"/home/dany/projekte/acs/grav/user/pages/01.kunden/audi/customer.de.md",
"/home/dany/projekte/acs/grav/bs-config.js",
"/home/dany/projekte/acs/grav/user/pages/01.kunden/audi/q1/default.md",
"/home/dany/projekte/acs/grav/user/pages/01.kunden/audi/p1/default.md",
"/home/dany/projekte/acs/grav/user/themes/acs/blueprints/item.yaml",
"/home/dany/projekte/acs/grav/user/themes/acs/blueprints/customer.yaml",
"/home/dany/projekte/acs/grav/user/themes/acs/blueprints/blog.yaml",
"/home/dany/projekte/acs/grav/start.sh",
"/home/dany/local-dev/grav/user/pages/01.kunden/porsche/customer.de.md",
"/home/dany/local-dev/grav/user/pages/01.kunden/customers.de.md",
"/home/dany/local-dev/grav/user/themes/acs/templates/blog.html.twig",
"/home/dany/local-dev/grav/user/pages/01.kunden/audi/customer.de.md",
"/home/dany/local-dev/grav/user/themes/acs/templates/modular/video.html.twig",
"/home/dany/local-dev/grav/user/pages/01.kunden/_video/video.md",
"/home/dany/local-dev/grav/user/pages/01.kunden/Audi/modular.de.md",
"/home/dany/local-dev/grav/user/themes/acs/templates/partials/base.html.twig",
"/home/dany/local-dev/grav/user/pages/01.kunden/modular.de.md",
"/home/dany/local-dev/grav/user/pages/01.kunden/_customer/customer.md",
"/home/dany/local-dev/grav/user/themes/quark/templates/partials/base.html.twig",
"/home/dany/local-dev/grav/user/pages/01.kunden/modular.html.twig",
"/home/dany/local-dev/grav/user/themes/acs/blueprints.yaml",
"/home/dany/local-dev/grav/user/themes/acs/acs.php",
"/home/dany/local-dev/grav/user/config/system.yaml",
"/home/dany/local-dev/grav/user/config/site.yaml",
"/home/dany/local-dev/grav/user/pages/03.test/default.md",
"/home/dany/local-dev/grav/user/pages/04.kunden/_customer/_customer-list.twig",
"/home/dany/local-dev/pixelcoud/cimme/CIMme/src/cimme-app.html",
"/home/dany/local-dev/pixelcoud/cimme/CIMme/bower.json",
"/home/dany/local-dev/pixelcoud/cimme/CIMme/package.json",
"/home/dany/Downloads/rvv-font-test.html",
"/home/dany/local-dev/pixelcoud/cimme/CIMme/polymer.json",
"/home/dany/local-dev/pixelcoud/cimme/CIMme/index.html",
"/home/dany/local-dev/pixelcoud/cimme/CIMme/build/default/index.html",
"/home/dany/local-dev/pixelcoud/cimme/CIMme/build/es6-bundled/index.html",
"/home/dany/local-dev/pixelcoud/cimme/CIMme/src/cimme-header.html",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/app.module.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/edit/edit.component.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/edit/subject/subject.component.ts",
"/home/dany/tmp/kaiser-waibel_wp_db-14092018_0934.sql",
"/home/dany/projekte/lideal/kaiser wibel/backup.zip",
"/home/dany/.cache/.fr-ZyfoWo/db119732_1.dump",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/in-memory-data.service.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/app-routing.module.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/app.component.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/nav/nav.component.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/nav/nav.component.html",
"/home/dany/projekte/ng-nl-tool/nl-tool/angular.json",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/styles.css",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/delete/delete.component.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/messages/messages.component.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/load/load.component.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/edit/edit.component.html",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/app.component.css",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/app.component.html",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/load/load.component.html",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/load/load.component.css",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/edit/subject/subject.component.html",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/edit/inline-edit/inline-edit.component.css",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/edit/newsletter.service.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/messages/messages.component.html",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/message.service.ts",
"/home/dany/projekte/ng-nl-tool/nl-tool/src/app/nav/nav.component.spec.ts",
"/home/dany/.config/sublime-text-3/Packages/User/TypeScript.sublime-settings"
],
"find":
{
"height": 39.0
},
"find_in_files":
{
"height": 430.0,
"where_history":
[
]
},
"find_state":
{
"case_sensitive": false,
"find_history":
[
],
"highlight": true,
"in_selection": false,
"preserve_case": false,
"regex": false,
"replace_history":
[
],
"reverse": false,
"show_context": true,
"use_buffer2": true,
"whole_word": false,
"wrap": true
},
"groups":
[
{
"selected": 0,
"sheets":
[
{
"buffer": 0,
"file": "5.html",
"semi_transient": false,
"settings":
{
"buffer_size": 10102,
"regions":
{
},
"selection":
[
[
7834,
7834
]
],
"settings":
{
"syntax": "Packages/HTML/HTML.sublime-syntax",
"translate_tabs_to_spaces": false
},
"translation.x": 0.0,
"translation.y": 4907.0,
"zoom_level": 1.0
},
"stack_index": 0,
"type": "text"
}
]
}
],
"incremental_find":
{
"height": 39.0
},
"input":
{
"height": 146.0
},
"layout":
{
"cells":
[
[
0,
0,
1,
1
]
],
"cols":
[
0.0,
1.0
],
"rows":
[
0.0,
1.0
]
},
"menu_visible": true,
"output.doc":
{
"height": 0.0
},
"output.find_results":
{
"height": 0.0
},
"pinned_build_system": "",
"project": "linux-kurs.sublime-project",
"replace":
{
"height": 74.0
},
"save_all_on_build": true,
"select_file":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
[
"",
"app/app.component.ts"
],
[
"serv",
"app/edit/newsletter.service.ts"
]
],
"width": 0.0
},
"select_project":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"select_symbol":
{
"height": 392.0,
"last_filter": "",
"selected_items":
[
],
"width": 833.0
},
"selected_group": 0,
"settings":
{
},
"show_minimap": false,
"show_open_files": true,
"show_tabs": true,
"side_bar_visible": false,
"side_bar_width": 259.0,
"status_bar_visible": true,
"template_settings":
{
}
}