16.04.2014 Views

Administración avanzada de GNU/Linux (PDF) - SW Computación

Administración avanzada de GNU/Linux (PDF) - SW Computación

Administración avanzada de GNU/Linux (PDF) - SW Computación

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ª FUOC • XP04/90785/00019<br />

Software libre<br />

La sintaxis básica <strong>de</strong> las estructuras <strong>de</strong> control es la siguiente:<br />

a) Estructura if...then, se evalúa la expresión y si se obtiene un valor<br />

cierto, entonces se ejecutan los commands.<br />

if [ expresion ]<br />

then<br />

commands<br />

fi<br />

b) Estructura if..then...else, se evalúa la expresión, y si se obtiene un<br />

valor <strong>de</strong> cierto, entonces se ejecutan los commands1 , en caso contrario<br />

se ejecutan los commands2:<br />

if [ expresion ]<br />

then<br />

commands1<br />

else<br />

commands2<br />

fi<br />

c) Estructura if..then...else if...else, misma utilización que la anterior,<br />

con anidamientos <strong>de</strong> estructuras if.<br />

if [ expresion ]<br />

then<br />

commands<br />

elif [ expresion2 ]<br />

then<br />

commands<br />

else<br />

commands<br />

fi<br />

ANOTACIONES<br />

Nota<br />

Los shells como Bash, ofrecen<br />

un conjunto amplio <strong>de</strong><br />

estructuras <strong>de</strong> control que<br />

los hace comparables a<br />

cualquier otro lenguaje.<br />

d) Estructura case select, estructura <strong>de</strong> selección múltiple según valor<br />

<strong>de</strong> selección (en case)<br />

case string1 in<br />

str1)<br />

commands;;<br />

str2)<br />

commands;;<br />

*)<br />

commands;;<br />

esac<br />

122

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!