From 87205c16f063cb543a2b16952125cd73b4923bd4 Mon Sep 17 00:00:00 2001 From: Daniel Schubert Date: Tue, 8 Jan 2019 13:08:27 +0100 Subject: [PATCH] 5 WIP --- 4.html | 2 +- 5.html | 126 ++++++++++++++++--- beispiele/{ => 4}/archive-dir.sh | 0 beispiele/{ => 4}/create_files_with_space.sh | 0 beispiele/{ => 4}/finduser.sh | 0 beispiele/{ => 4}/mysystem.sh | 0 beispiele/{ => 4}/recursive-grep-in-file.sh | 0 beispiele/{ => 4}/remove-spaces.sh | 0 beispiele/4/rename-jpg.sh | 17 +++ beispiele/5/01-vars.sh | 8 ++ beispiele/5/02-comments.sh | 10 ++ beispiele/5/recursive-func.sh | 28 +++++ beispiele/5/while-menu.sh | 27 ++++ notes.txt | 19 --- 14 files changed, 201 insertions(+), 36 deletions(-) rename beispiele/{ => 4}/archive-dir.sh (100%) rename beispiele/{ => 4}/create_files_with_space.sh (100%) rename beispiele/{ => 4}/finduser.sh (100%) rename beispiele/{ => 4}/mysystem.sh (100%) mode change 100644 => 100755 rename beispiele/{ => 4}/recursive-grep-in-file.sh (100%) rename beispiele/{ => 4}/remove-spaces.sh (100%) create mode 100644 beispiele/4/rename-jpg.sh create mode 100644 beispiele/5/01-vars.sh create mode 100644 beispiele/5/02-comments.sh create mode 100644 beispiele/5/recursive-func.sh create mode 100644 beispiele/5/while-menu.sh delete mode 100644 notes.txt diff --git a/4.html b/4.html index 9dc58f9..30817c6 100644 --- a/4.html +++ b/4.html @@ -219,7 +219,7 @@ USER Benutzername -
+
#!/bin/bash
 clear
 echo "Diese Infos werden von mysystem.sh bereitgestellt."
diff --git a/5.html b/5.html
index f523418..03bfec7 100644
--- a/5.html
+++ b/5.html
@@ -40,7 +40,7 @@
 				

LINUX

Das universelle Betriebssystem

-

Eine Einführung - Teil 4 +

Eine Einführung - Teil 5

Deutsche Angestellten Akademie

@@ -51,25 +51,119 @@
-

vim und emacs

-

Die mächtigen Unix Editoren

+

Bash scripting - Fortsetzung

-
-

vim

-
    -
  • ein Editor für die shell
  • -
  • immer da, oft in der alten Variante „vi“
  • -
  • Vi IMproved
  • -
  • komplett per Kürzel steuerbar
  • -
  • umfassend anpassbar
  • -
  • erweiterbar
  • -
  • syntax highlighting
  • -
  • vim ist einfach cool ;-)
  • -
- +
+

LINKS

+ +

http://tldp.org/LDP/abs/html/complexfunct.html + +

http://programmingexamples.wikidot.com/bash-scripting#toc24 + +

https://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_für_Anfänger/#Quoting + +

+ - script kontrolle ( strg-z etc ) + - input + - parameter + - functions + + - kontrollstrukturen + - +
+ +
+

Variablen

+
#!/bin/bash
+ 
+x=10            #NICHT x = 10 -> keine Leerzeichen!
+X=20            #variablen sind Case Sensitive
+$y=             #NULL variable
+echo "x = $x"
+echo "X = $X"
+echo "y = $y"
+
+ +
+

Kommentare

+

+#!/bin/bash
+# Diese Zeile ist ein Kommentar
+echo "A comment will follow." # Comment here.
+echo "The # here does not begin a comment."
+echo 'The # here does not begin a comment.'
+echo The \# here does not begin a comment.
+echo The # here begins a comment.
+ 
+echo ${PATH#*:}       # Parameter substitution, not a comment.
+echo $(( 2#101011 ))  # Base conversion, not a comment.
+					
+					
+
+ +
+

Quotes

+ +
    +
  • Double Quotes: " " -Anything enclose in double quotes removed meaning of that characters (except \ and $).
  • +
  • Single quotes: ' ' - Enclosed in single quotes remains unchanged.
  • +
  • Back quote: ` ` - To execute command
  • +
+
+ +
+

Input - Output redirection

+ +
    +
  • > : output in Datei. Best. Datei wird überschrieben!
  • +
  • >> : output an Datei anhängen.
  • +
  • < : Kommando Input aus Datei lesen
  • +
+
#!/bin/bash
+echo "ls > file_list"
+ls > file_list
+ 
+echo "ls -la >> file_list"
+ls -la >> file_list
+ 
+echo "cat < file_list"
+cat < file_list
+ + +
+
+ - arithmetik + + let "m = 4 * 1024";echo $m + + let "m += 15" + let "m -= 3" + let "m /= 5" + let "m %= 10" + let "m++" + let "m--" + + let "k = (m < 9) ? 0 : 1" + condition ? value-if-true : value-if-false + + Floating Poin: + echo "32.0 + 1.4" | bc + + echo `expr $m + 18` + m=`expr $m + 18` + + (( m *= 4 )) + +
+
+ +
+ + +

Die 5 Level eines Vim Magiers

    diff --git a/beispiele/archive-dir.sh b/beispiele/4/archive-dir.sh similarity index 100% rename from beispiele/archive-dir.sh rename to beispiele/4/archive-dir.sh diff --git a/beispiele/create_files_with_space.sh b/beispiele/4/create_files_with_space.sh similarity index 100% rename from beispiele/create_files_with_space.sh rename to beispiele/4/create_files_with_space.sh diff --git a/beispiele/finduser.sh b/beispiele/4/finduser.sh similarity index 100% rename from beispiele/finduser.sh rename to beispiele/4/finduser.sh diff --git a/beispiele/mysystem.sh b/beispiele/4/mysystem.sh old mode 100644 new mode 100755 similarity index 100% rename from beispiele/mysystem.sh rename to beispiele/4/mysystem.sh diff --git a/beispiele/recursive-grep-in-file.sh b/beispiele/4/recursive-grep-in-file.sh similarity index 100% rename from beispiele/recursive-grep-in-file.sh rename to beispiele/4/recursive-grep-in-file.sh diff --git a/beispiele/remove-spaces.sh b/beispiele/4/remove-spaces.sh similarity index 100% rename from beispiele/remove-spaces.sh rename to beispiele/4/remove-spaces.sh diff --git a/beispiele/4/rename-jpg.sh b/beispiele/4/rename-jpg.sh new file mode 100644 index 0000000..ab02b03 --- /dev/null +++ b/beispiele/4/rename-jpg.sh @@ -0,0 +1,17 @@ +#!/bin/bash +suf=$1 +if [ $# -gt 0 ] + then + for f in *.$suf; do + bn=`basename "$f" .$suf | sed 's/IMG_//'` + new=$bn.$suf + echo "neuer Dateiname:" + echo $new + mv "$f" $new + done + else + echo "Kein Suffix gegeben!!" + echo "Verwendung: strip-space.sh SUFFIX" + echo "Beende ...." + exit 1 +fi diff --git a/beispiele/5/01-vars.sh b/beispiele/5/01-vars.sh new file mode 100644 index 0000000..ec5754d --- /dev/null +++ b/beispiele/5/01-vars.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +x=10 #NOT x = 10 no spaces +X=20 #variables are case sensitive +$y= #NULL variable +echo "x = $x" +echo "X = $X" +echo "y = $y" \ No newline at end of file diff --git a/beispiele/5/02-comments.sh b/beispiele/5/02-comments.sh new file mode 100644 index 0000000..545a056 --- /dev/null +++ b/beispiele/5/02-comments.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# This line is a comment. +echo "A comment will follow." # Comment here. +echo "The # here does not begin a comment." +echo 'The # here does not begin a comment.' +echo The \# here does not begin a comment. +echo The # here begins a comment. + +echo ${PATH#*:} # Parameter substitution, not a comment. +echo $(( 2#101011 )) # Base conversion, not a comment. \ No newline at end of file diff --git a/beispiele/5/recursive-func.sh b/beispiele/5/recursive-func.sh new file mode 100644 index 0000000..2056e9e --- /dev/null +++ b/beispiele/5/recursive-func.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Beispiel für Rekursive Funktion + +#Funktions-Definition +function sum() { + if [ -z "$2" ]; then + + #Rückgabewert + echo $1 + + else + a=$1; + + #Parameter werden nach links verschoben : orkus <- $1 , $1 <- $2 + shift; + + #Funktion ruft sich selbst auf - Rekursion + #Ergebnis. b == 2 + b=`sum $@` + + + echo `expr $a + $b` # <- 1 + 2 + fi +} + +# Funktions-Aufruf mit 2 Parametern +sum 1 2 diff --git a/beispiele/5/while-menu.sh b/beispiele/5/while-menu.sh new file mode 100644 index 0000000..404e92a --- /dev/null +++ b/beispiele/5/while-menu.sh @@ -0,0 +1,27 @@ +# Script to create simple menus and take action according to that selected +# menu item +# +while : + do + clear + echo "-------------------------------------" + echo " Main Menu " + echo "-------------------------------------" + echo "[1] Show Todays date/time" + echo "[2] Show files in current directory" + echo "[3] Show calendar" + echo "[4] Start editor to write letters" + echo "[5] Exit/Stop" + echo "=======================" + echo -n "Enter your menu choice [1-5]: " + read yourch + case $yourch in + 1) echo "Today is `date` , press a key. . ." ; read ;; + 2) echo "Files in `pwd`" ; ls -l ; echo "Press a key. . ." ; read ;; + 3) cal ; echo "Press a key. . ." ; read ;; + 4) vi ;; + 5) exit 0 ;; + *) echo "Opps!!! Please select choice 1,2,3,4, or 5"; + echo "Press a key. . ." ; read ;; + esac +done \ No newline at end of file diff --git a/notes.txt b/notes.txt deleted file mode 100644 index 7e3a93c..0000000 --- a/notes.txt +++ /dev/null @@ -1,19 +0,0 @@ - wiederholugn - -regexp - -bash config - -scripting - - - -cp `find . -name "*.jpg"` neuer_ordner - - -for FILE in *.JPG -do - NEWFILE2=`echo "$FILE" | sed 's/.(*)/\-/'` - echo "$NEWFILE2" - mv "$FILE" "$NEWFILE2" -done