UF2: Gestió de la informació i de recursos en una xarxa
Resultats d'aprenentatge:
- Assegura la informació del sistema.
- Centralitza la informació en servidors administrant estructures de dominis i analitzant-ne els avantatges.
Automatització
Expressions aritmètiques
expr (man expr)
És la forma més universal. Com que és una comanda, podria ser una mica lenta en bucles. Cal escapar els meta-caràcters, com el *, i separar els operands i operacions amb espais.
$ expr 2 + 2 \* 9
let (help let)
Cada argument és una expressió a avaluar. Es poden utilitzar les variables amb i sense $.
$ let x=4 y=5 z=x+y
$ echo "$x $y $z"
$((...))
És la forma més moderna.
$ echo $((2 + 2 * 9))
$ echo $((2+2*9))
$ x=2; y=3; echo $((x*y))
Avaluació de parèntesis
$(...) means execute the command in the parenthesis in a subshell and return its stdout. Example:
$ echo "The current date is $(date)"
The current date is Mon Jul 6 14:27:59 PDT 2015
(...) means run the commands listed in the parenthesis in a subshell. Example:
$ a=1; (a=2; echo "inside: a=$a"); echo "outside: a=$a"
inside: a=2
outside: a=1
$((...)) means perform arithmetic and return the result of the calculation. Example:
$ a=$((2+3)); echo "a=$a"
a=5
((...)) means perform arithmetic, possibly changing the values of shell variables, but don't return its result. Example:
$ ((a=2+3)); echo "a=$a"
a=5
${...} means return the value of the shell variable named in the braces. Example:
$ echo ${SHELL}
/bin/bash
{...} means execute the commands in the braces as a group. Example:
$ false || { echo "We failed"; exit 1; }
We failed