...
Cursor movements in command line
emacs mode:
<Esc> . | repeat last word of previous command |
Ctrl-a | jump to beginning of line |
Ctrl-e | jump to end of line |
Ctrl-r | search backwards in command history |
Ctrl-c | interrupt current command/process |
Control structures
if then else
...
Arithmetic expression examples ( a=2 ):
(( a == 3 ))
(( b != 3 ))
(( $a >= 3 ))
In Arithmetic expressions '(( ... ))' it is not necessary to put the '$' in front of variables since strings are not allowed so all strings are assumed to be variables.
String expressions examples ( abc="Bonjour" ):
equal:
[[ "$abc" == "Hello" ]]
not equal:
[[ "$abc" != "Hello" ]]
The more common but less recommended way is:
[ $a -le 3 ]
resp.
[ "$abc" -nq "Hello" ]
Note: It is mandatory to keep a 'space' just before and after the double and single square brackets!!!
and: &&
or: ||
If you want to know more about the comparison operators try:
man test
or
man bash -> CONDITIONAL EXPRESSIONS
case-statement
A case statement is a conditional control structure that allows a selection to be made between several sets of program statements. It is a popular alternative to the if-then-else statement when you need to evaluate multiple different choices.
Volet |
---|
case test_string in pattern_1 | pattern_2 ) statement(s) ;; pattern_23 ) statement(s) ;; * ) default_statement(s) ;; esac |
...
The pipe character '|' serves here as an "or".
The last line of each statement needs to be finished with ';;' at the end.
Examples:
Volet |
---|
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
for loop
for var in word1 word2 ... wordN ; do
Statement(s) to be executed for every word.
done
Examples:
for hour in 00 06 12 18 ; do
echo $hour
done
touch dm_01 dm_02
for fine in dm* ; do
echo $file
done
...