Revision history for Bash
Additions:
==a==Console colors==a==
[[PythonBashConsoleColor Bash color output in Python]]
[[PythonBashConsoleColor Bash color output in Python]]
Additions:
echo "Test with unknown command should fail."
foofoo 2> /dev/null
exitcode=$?
echo $exitcode
if [ $exitcode -ne 0 ]; then
echo "Error"
echo "OK"
echo " "
echo "Test with successfull executed command should return 0."
ls > /dev/null
exitcode=$?
echo $exitcode
if [ $exitcode -ne 0 ]; then
echo "Error"
echo "OK"
Result
Test with unknown command should fail.
127
Error
Test with successfull executed command should return 0.
0
OK
foofoo 2> /dev/null
exitcode=$?
echo $exitcode
if [ $exitcode -ne 0 ]; then
echo "Error"
echo "OK"
echo " "
echo "Test with successfull executed command should return 0."
ls > /dev/null
exitcode=$?
echo $exitcode
if [ $exitcode -ne 0 ]; then
echo "Error"
echo "OK"
Result
Test with unknown command should fail.
127
Error
Test with successfull executed command should return 0.
0
OK
Additions:
==a==Create enumerated files and directories==a==
mkdir dir{0..9}
dir0
dir1
dir2
...
dir9
mkdir dir{0..9}
dir0
dir1
dir2
...
dir9
Additions:
==a==BASH error handling==a==
Deletions:
Additions:
==a==BASH error handlin==a==
Exit status
%%$?%%
Exit status
%%$?%%
Additions:
Endless loop
while [ true ]
...
while [ true ]
...
Additions:
Mit IF
if [ "$a" -gt "0" ]; then
echo 'true'
else
echo 'false'
fi
if [ "$a" -gt "0" ]; then
echo 'true'
else
echo 'false'
fi
Additions:
==a==Parallel processing in BASH==a==
http://stackoverflow.com/questions/13296863/difference-between-wait-and-sleep
sleep 10 &
wait
http://stackoverflow.com/questions/13296863/difference-between-wait-and-sleep
sleep 10 &
wait
Additions:
Besser
zahl=1
zahl=$(( $zahl + 1 ))
zahl=1
zahl=$(( $zahl + 1 ))
Additions:
==a==While==a==
while [ condition ]
do
[Kommandos]
done
while [ condition ]
do
[Kommandos]
done
Additions:
Zahl inkrementieren
String zuweisen
set A=Dies ist ein Test
echo %A%
set B=%A%
echo %B%
Pfad hinzufügen
set PATH=%PATH%;C:\rnsget
Set alle Variablen auflisten
set
if [ "$a" -eq "$b" ]
if [ "$a" -ne "$b" ]
if [ "$a" -gt "$b" ]
if [ "$a" -ge "$b" ]
if [ "$a" -lt "$b" ]
if [ "$a" -le "$b" ]
(("$a" < "$b"))
(("$a" <= "$b"))
(("$a" > "$b"))
(("$a" >= "$b"))
if [ "$a" = "$b" ]
if [ "$a" == "$b" ]
if [ "$a" != "$b" ]
This operator uses pattern matching within a [[ ... ]] construct.
if [[ "$a" < "$b" ]]
if [ "$a" < "$b" ]
Note that the "<" needs to be escaped within a [ ] construct.
if [[ "$a" > "$b" ]]
if [ "$a" > "$b" ]
Note that the ">" needs to be escaped within a [ ] construct.
See Example 26-11 for an application of this comparison operator.
exp1 -a exp2 returns true if both exp1 and exp2 are true.
exp1 -o exp2 returns true if either exp1 or exp2 are true.
This is identical in effect to -e. It has been "deprecated," and its use is discouraged.
This test option may be used to check whether the stdin ([ -t 0 ]) or stdout ([ -t 1 ]) in
a given script is a terminal.
If a directory has the sgid flag set, then a file created within that directory belongs to the group that
owns the directory, not necessarily to the group of the user who created the file. This may be useful
for a directory shared by a workgroup.
file f1 is newer than f2
file f1 is older than f2
files f1 and f2 are hard links to the same file
String zuweisen
set A=Dies ist ein Test
echo %A%
set B=%A%
echo %B%
Pfad hinzufügen
set PATH=%PATH%;C:\rnsget
Set alle Variablen auflisten
set
if [ "$a" -eq "$b" ]
if [ "$a" -ne "$b" ]
if [ "$a" -gt "$b" ]
if [ "$a" -ge "$b" ]
if [ "$a" -lt "$b" ]
if [ "$a" -le "$b" ]
(("$a" < "$b"))
(("$a" <= "$b"))
(("$a" > "$b"))
(("$a" >= "$b"))
if [ "$a" = "$b" ]
if [ "$a" == "$b" ]
if [ "$a" != "$b" ]
This operator uses pattern matching within a [[ ... ]] construct.
if [[ "$a" < "$b" ]]
if [ "$a" < "$b" ]
Note that the "<" needs to be escaped within a [ ] construct.
if [[ "$a" > "$b" ]]
if [ "$a" > "$b" ]
Note that the ">" needs to be escaped within a [ ] construct.
See Example 26-11 for an application of this comparison operator.
exp1 -a exp2 returns true if both exp1 and exp2 are true.
exp1 -o exp2 returns true if either exp1 or exp2 are true.
This is identical in effect to -e. It has been "deprecated," and its use is discouraged.
This test option may be used to check whether the stdin ([ -t 0 ]) or stdout ([ -t 1 ]) in
a given script is a terminal.
If a directory has the sgid flag set, then a file created within that directory belongs to the group that
owns the directory, not necessarily to the group of the user who created the file. This may be useful
for a directory shared by a workgroup.
file f1 is newer than f2
file f1 is older than f2
files f1 and f2 are hard links to the same file
Deletions:
if [ "$a" -ne "$b" ]
if [ "$a" -gt "$b" ]
if [ "$a" -ge "$b" ]
if [ "$a" -lt "$b" ]
if [ "$a" -le "$b" ]
(("$a" < "$b"))
(("$a" <= "$b"))
(("$a" > "$b"))
(("$a" >= "$b"))
if [ "$a" = "$b" ]
if [ "$a" == "$b" ]
if [ "$a" != "$b" ]
This operator uses pattern matching within a [[ ... ]] construct.
if [[ "$a" < "$b" ]]
if [ "$a" < "$b" ]
Note that the "<" needs to be escaped within a [ ] construct.
if [[ "$a" > "$b" ]]
if [ "$a" > "$b" ]
Note that the ">" needs to be escaped within a [ ] construct.
See Example 26-11 for an application of this comparison operator.
exp1 -a exp2 returns true if both exp1 and exp2 are true.
exp1 -o exp2 returns true if either exp1 or exp2 are true.
This is identical in effect to -e. It has been "deprecated," and its use is discouraged.
This test option may be used to check whether the stdin ([ -t 0 ]) or stdout ([ -t 1 ]) in
a given script is a terminal.
If a directory has the sgid flag set, then a file created within that directory belongs to the group that
owns the directory, not necessarily to the group of the user who created the file. This may be useful
for a directory shared by a workgroup.
file f1 is newer than f2
file f1 is older than f2
files f1 and f2 are hard links to the same file
Additions:
Zählen
for (( i=4; i<20; i++ )); do echo $i ; done
for (( i=4; i<20; i++ )); do echo $i ; done
Deletions:
Additions:
BashLinks
No Differences
Additions:
||A < in.txt|| Der Inhalt von in.txt wird als Eingabe an A weitergeleitet||
Deletions:
Additions:
||A "">>"" out.txt|| Die Ausgabe (Fehlermeldungen ausgenommen) von A an den Inhalt der Datei out.txt anhängen||
Deletions:
Additions:
==a==Standard-IO, Error-IO, File-IO und Pipes==a==
||A||Befehl ausführen und auf Beendigung warten ||
||A & || Befehl im Hintergrund ausführen||
||A ; B ||Befehl A ausführen, dann Befehl B||
||(A; B)||Befehle als Gruppe in einer Shell ausgeführt||
||A ""|"" B || Pipe; Die Ausgabe von A wird an B als Eingabe weitergeleitet||
||A $(B) || Die Ausgabe von B wird zu Befehlsargumenten von A||
||A && B || B wird ausgeführt, wenn A ohne Fehler ausgeführt wurde||
||A ""||"" B|| B wird ausgeführt, wenn bei A ein Fehler aufgetreten ist||
||A > out.txt|| Die Ausgabe (Fehlermeldungen ausgenommen) von A in die Datei out.txt schreiben; Die Datei wird überschrieben||
||A >> out.txt|| Die Ausgabe (Fehlermeldungen ausgenommen) von A an den Inhalt der Datei out.txt anhängen||
||A 2> out.txt|| Die Fehlermeldungen von A an in die Datei out.txt schr iben||
||A < in.txt|| Der Inhalt von in.txt wird als Eingabe an B weitergeleitet||
||A||Befehl ausführen und auf Beendigung warten ||
||A & || Befehl im Hintergrund ausführen||
||A ; B ||Befehl A ausführen, dann Befehl B||
||(A; B)||Befehle als Gruppe in einer Shell ausgeführt||
||A ""|"" B || Pipe; Die Ausgabe von A wird an B als Eingabe weitergeleitet||
||A $(B) || Die Ausgabe von B wird zu Befehlsargumenten von A||
||A && B || B wird ausgeführt, wenn A ohne Fehler ausgeführt wurde||
||A ""||"" B|| B wird ausgeführt, wenn bei A ein Fehler aufgetreten ist||
||A > out.txt|| Die Ausgabe (Fehlermeldungen ausgenommen) von A in die Datei out.txt schreiben; Die Datei wird überschrieben||
||A >> out.txt|| Die Ausgabe (Fehlermeldungen ausgenommen) von A an den Inhalt der Datei out.txt anhängen||
||A 2> out.txt|| Die Fehlermeldungen von A an in die Datei out.txt schr iben||
||A < in.txt|| Der Inhalt von in.txt wird als Eingabe an B weitergeleitet||
Deletions:
Additions:
==a==Vordefinierte Variablen==a==
cd `dirname $0` #Change to script directory or any other directory
# do something else
cd $OLDDIR #Change back to old dir
cd `dirname $0` #Change to script directory or any other directory
# do something else
cd $OLDDIR #Change back to old dir
Deletions:
cd `dirname $0` #Change to script directory
pwd # Print current dir
cd $OLDDIR #Change to old dir
pwd # Print current dir
==a==Vordefiniert==a==
Additions:
Merke altes Verzeichnis
OLDDIR=`pwd` #Save current dir
pwd # Print current dir
cd `dirname $0` #Change to script directory
pwd # Print current dir
cd $OLDDIR #Change to old dir
pwd # Print current dir
OLDDIR=`pwd` #Save current dir
pwd # Print current dir
cd `dirname $0` #Change to script directory
pwd # Print current dir
cd $OLDDIR #Change to old dir
pwd # Print current dir