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.

...

You can evaluate a command and store the answer in a variable.
For example if you want to store the current date in a variable you can use:

      current_date=`date`
or the newer method:
      current_date=$(date)
      echo $current_date 

Evaluate a variable

If you have a variable which contains a command you can evaluate (execute) this command with 'eval':

     

Arithmetic

Arithmetic calculations

Arithmetic calculation can be done within double round brackets. Examples:

            year=2013
      next_year=$((  year +))
or
      (( next_year = year + 1 ))
      echo $next_year
          2014

% : modulo / remainder
      echo $(( 10 % 3 ))
          1

Just be careful and never try arithmetic operations on numbers starting with a zero!!!

...

'\' prevents the following character from being "interpreted". There are several "special characters" (see above) in shell which have a certain "meaning" and functions as little "commands".
Unfortunately '\' has different meanings depending on where/how it gets used.
Examples:
    $  person=Alex
    $  echo $person
    Alex
    $  echo \$person
    $person              => No evaluation done !!!
    $  echo "\$person"
    $person              => No evaluation done !!!
    $  echo '\$person'
    Alex                   => Evaluation done !!!

When used as the very last character in a line it will surpress the "new line".
    $ cat > text_file << EOF
    > Hello
    > How are you?
    > EOF
    $ cat text_file
    Hello
    How are you?

    $ cat > text_file << EOF
    > Hello, \
    > how are you?
    > EOF
    $ cat text_file
    Hello, how are you?

...