11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

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.

echo<br />

alias lll="ls -l $<strong>di</strong>rectory$prefisso"<br />

Capitolo 24. Alias<br />

echo "Prova dell’alias \"lll\":"<br />

lll # Lungo elenco <strong>di</strong> tutti i file presenti in /usr/X11R6/bin che<br />

#+ iniziano con mk.<br />

# Un alias è in grado <strong>di</strong> gestire le variabili concatenate<br />

#+ - e anche il carattere jolly.<br />

TRUE=1<br />

echo<br />

if [ TRUE ]<br />

then<br />

alias rr="ls -l"<br />

echo "Prova dell’alias \"rr\" all’interno <strong>di</strong> un enunciato if/then:"<br />

rr /usr/X11R6/bin/mk* #* Messaggio d’errore!<br />

# Gli alias non vengono espansi all’interno <strong>di</strong> enunciati composti.<br />

echo "Comunque, l’alias precedentemente espanso viene ancora riconosciuto:"<br />

ll /usr/X11R6/bin/mk*<br />

fi<br />

echo<br />

conto=0<br />

while [ $conto -lt 3 ]<br />

do<br />

alias rrr="ls -l"<br />

echo "Prova dell’alias \"rrr\" in un ciclo \"while\":"<br />

rrr /usr/X11R6/bin/mk* #* Anche in questo caso l’alias non viene espanso.<br />

# alias.sh: line 61: rrr: command not found<br />

let conto+=1<br />

done<br />

echo; echo<br />

alias xyz=’cat $0’ # Lo script visualizza sé stesso.<br />

# Notate il quoting forte.<br />

xyz<br />

# Questo sembra funzionare,<br />

#+ sebbene la documentazione <strong>Bash</strong> suggerisca il contrario.<br />

#<br />

# In ogni caso, come ha evidenziato Steve Jacobson,<br />

#+ il parametro "$0" viene espanso imme<strong>di</strong>atamente alla<br />

#+ <strong>di</strong>chiarazione dell’alias.<br />

exit 0<br />

466

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

Saved successfully!

Ooh no, something went wrong!