User Tools

Site Tools


shell_progammierung

This is an old revision of the document!


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

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"
  RETURN $ERG
}
ERG=`summe 5 6` 
echo $ERG

Variablen

HISTSIZE 
TMOUT
ENV
OSTYPE
HOSTTYPE

Umleiten

STDIN < 
STDOUT > >> 
STDERR 2> 

Example: bypass STDERR to STDOUT

2>&1

Example: bypass STDOUT and STDERR

>/dev/null 2>&1

IF

Comparison:

if [ $VAR == "string" ]
   machwas
fi
if [ $VAR -eq 5 ]
   machwas
fi

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

Check Files or Directories

test -d directory
test -e file
test -f file
test ! ( ausdruck)

WHILE

 while [ expression ]
 do
     dosomething
 done
shell_progammierung.1283937815.txt.gz · Last modified: 2021/04/24 07:38 (external edit)