Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.

...

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

Volet
if

...

   expression_1; then
   Statement(s) to be executed if expression 1 is true
[elif expression_2; then
   Statement(s) to be executed if expression 2 is true
elif expression_3; then
   Statement(s) to be executed if expression 3 is true
else
   Statement(s) to be executed if no expression is true]
fi

'elifexpression ; then' and 'else' are optional!!!expressions can look like this

Example 'expressions':

Arithmetic expression examples ( a=2 ): 
    (( a == 3 )) 
    (( b != 3 ))
    (( $a >= 3 ))
In Arithmetic expressions '(( ... ))' it is not necessary to put the '$' infront in front of variables since strings are not allowed so all strings are assumed to be variables anyways.

String expressions examples ( abc="Bonjour" ):
equal:
    [[ "$abc" == "Hello" ]]
not equal:
    [[ "$abc" != "Hello" ]]

The more common but less recomended 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

Volet
case test_string in
    pattern_1)  statement(s) ;;
    pattern_2)  statement(s) ;;
    *) default_statement(s) ;;
esac



Examples:

    mon="Jan"
    case "$mon" in
        "Jan") echo January
                   month=January ;;
        "Feb") echo February
                    month=February ;;
        *) echo "month not known" ;;
    esac


    #  Determine number of days per month
    case ${month} in
      04|06|09|11) days=30 ;;
      02)          if   (( year % 4 == 0 )) && \
                      ( (( year % 100 != 0 )) || (( year % 400 == 0 )) ) ; then
                     days=29
                   else
                     days=28
                   fi ;;
      *)           days=31 ;;
    esac


...