User Tools

Site Tools


shell_progammierung

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
shell_progammierung [2010/09/06 12:22] – created michaelshell_progammierung [2021/04/24 07:40] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Shell Programmierung (bash) ====== ====== Shell Programmierung (bash) ======
 +
 +==== Abarbeitung der Kommandozeile ====
 +| Read until the first command separator | & && \| \| ; < > |
 +| Split the command | cat /etc/passwd \| wc -l |
 +| substitute variables | $MYVAR wird durch Wert ersetzt |
 +| substitute commands | Backticks oder () |
 +| stdin, stdout and stderr| re(>/dev/null, 2>&1,...)|
 +| Zuweisungen an Variablen durchführen| |
 +| Sonderzeichen ersetzen| Sonderzeichen wie *, ?, [] werden ersetzt. Ausser Sie stehen in "" |
 +| Fertiges Kommando ausführen |  |
 +
 +==== AWK ====
 +
 +|FS|Separator|
 +|RS|Record Sepatator. Normally Linbreak (\n)|
 +|NF|Number of Fields in a Record|
 +|NR|Number of active Record|
 +|ARGV|Array of all awk parameters|
 +|ARGC|number of all awk parameters|
 +|OFS|Output field separator|
 +|ORS|Output record separator|
 +
 +
 +   awk '{print $0}'
 +   df -hk | egrep "\/$" | awk '{print $5}'
 +   df -hk | awk '/sda/{print $5}'
 +   df -hk | awk 'NR>1{print $1,$3,$7}'
 +
 +==== Commandos ====
 +|exec||
 +|break||
 +|continue||
 +|declare||
 +|eval||
 +|getops||
 +|let||
 +|login|| 
 +|umask||
 +|readonly||
 +|trap||
 +|type||
 +|typset||
 +|exit||
 +
 +==== Funktionen ====
 +
 +  summe()
 +  {
 +    MYVAR1=$1
 +    MYVAR2=$2
 +    "let ERG=$MYVAR1+$MYVAR2"
 +    ECHO $ERG
 +  }
 +  ERG=`summe 5 6` 
 +  echo $ERG
 +
 +
 +
 +
 +==== Variablen ====
 +
 +  HISTSIZE 
 +  TMOUT
 +  ENV
 +  OSTYPE
 +  HOSTTYPE
  
 ==== Umleiten ==== ==== Umleiten ====
Line 7: Line 73:
   STDERR 2>    STDERR 2> 
  
-Bsp: STDERR auf STDOUT+Examplebypass STDERR to STDOUT
   2>&1   2>&1
 +
 +Example: bypass STDOUT and STDERR
 +  >/dev/null 2>&1
  
 ==== IF ==== ==== IF ====
Line 20: Line 89:
   fi   fi
 Weitere Parameter: -lt, -gt, !=, <, > Weitere Parameter: -lt, -gt, !=, <, >
 +
 +==== Meta-Zeichen ====
 +
 +  ?(string) 0-1mal string
 +  *(string) x-mal string
 +  +(string) 1-xmal string
 +  @(string) 1mal string
 +  !(string) nicht string
  
 ==== TEST-Command ==== ==== TEST-Command ====
Line 35: Line 112:
 ==== WHILE ==== ==== WHILE ====
  
 +   while [ expression ]
 +   do
 +       dosomething
 +   done
 +   
 +==== WHILE lines in file ====
  
 +   while read i; do
 +      echo $i
 +   done < list.txt
shell_progammierung.1283775748.txt.gz · Last modified: 2021/04/24 07:38 (external edit)