Bash Programmierung
http://freeos.com/guides/lsst/ -> Shell
http://www.tldp.org/LDP/abs/html/ -> Advanced Shell Programming
#!/bin/bash
variable="das ist ein test"
echo $variable
echo -e "\n" -> neue Zeile
read variable2
echo "$@" -> returns the options given with the command
echo "$1" -> returns the first option
//arrays
MYARRAY[0]=`ls -fl`
echo ${MYARRAY[0]}
//strings
echo $test | cut '-d ' -f1 -> gibt erster teil des strings bis zum 1. Leerschlag zurück -> '-d '
echo $test | cut -b3 -> gibt den 3. Buchstaben zurück
echo $test | cut -b1-3 -> gibt den 1.-3. Buchstaben zurück
echo ${string:3} -> gibt $string ab 3. Buchstaben zurück
echo ${string:3:4} -> gibt $string ab 3. Buchstaben zurück von einer Länge für 4 Buchstaben
string="${string/old/new}" -> replace substring
string="${string//old/new}" -> replace all substrings
expr length "$variable" -> returns lenght of string
//string ersetzen und in neues file speichern
sed -e "s/IPA/$ip/" /root/db.imboden.wydenvs.ch.orig > db.tmp
//while loop
i=1
while [ $i -le 10 ]
do
echo $i
i=`expr $i + 1`
done
-eq is equal to 5 == 6
-ne is not equal to 5 != 6
-lt is less than 5 < 6
-le is less than or equal to
-gt is greater than 5 > 6
-ge is greater than or equal to 5 >= 6
//folder loop
for FILE in "$FOLDER/"*; do
echo $FILE
done
//if else
if [ "$variable" = "1" ]
then
make sth.
else
make sth. else
fi
//test if input is an integer
test "$1" -ge 0 -o "$1" -lt 0 2>&- && echo "$1" is an integer
//check if folder exists
if [ ! -e $folder ]
//datum
datum=$(date +"%Y")-$(date +"%m")-$(date +"%d")
//textdatei in string
Variable="$(cat Textdatei)"
//block von A bis B auf Datei F ausschneiden
awk '/A/,/B/{ if (/A/ || /B/) next; print }' F > G
//alle Zeichen nach einem bestimmten Wort löschen
sed 's/Elapsed Time.*//'
//Anzahl Zeilen einer Datei auslesen
cat test.html | wc -m
