diff options
Diffstat (limited to 'it_IT.ISO8859-15/books/unix-introduction/shell-programming/chapter.xml')
-rw-r--r-- | it_IT.ISO8859-15/books/unix-introduction/shell-programming/chapter.xml | 122 |
1 files changed, 60 insertions, 62 deletions
diff --git a/it_IT.ISO8859-15/books/unix-introduction/shell-programming/chapter.xml b/it_IT.ISO8859-15/books/unix-introduction/shell-programming/chapter.xml index b00d3a97df..6764225a70 100644 --- a/it_IT.ISO8859-15/books/unix-introduction/shell-programming/chapter.xml +++ b/it_IT.ISO8859-15/books/unix-introduction/shell-programming/chapter.xml @@ -4,11 +4,10 @@ $FreeBSD$ --> - -<chapter id="shell-programming"> +<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" xml:id="shell-programming"> <title>Programmazione di shell</title> - <sect1 id="shell-programming-scripts"> + <sect1 xml:id="shell-programming-scripts"> <title>Script di shell</title> <para>Si possono scrivere programmi di shell creando script contenenti @@ -35,14 +34,14 @@ settando gli opportuni bit sul file con il comando &man.chmod.1;, esempio:</para> - <screen>&prompt.user; <userinput>chmod +x <replaceable>shell_script</replaceable></userinput></screen> + <screen>&prompt.user; <userinput>chmod +x shell_script</userinput></screen> <para>All'interno degli script il simbolo # indica un commento da quel punto fino alle fine della linea; #! è un caso speciale se trovato come primo carattere del file.</para> </sect1> - <sect1 id="shell-programming-sett-param-val"> + <sect1 xml:id="shell-programming-sett-param-val"> <title>Settare i valori dei parametri</title> <para>I valori di un parametro, ad esempio <literal>param</literal>, sono @@ -62,10 +61,10 @@ <tbody> <row> - <entry><command>param=<replaceable>valore</replaceable></command></entry> + <entry><command>param=valore</command></entry> <entry><command>set param = - <replaceable>valore</replaceable></command></entry> + valore</command></entry> </row> </tbody> </tgroup> @@ -92,7 +91,7 @@ Wed</screen> <literal>$param</literal> o <literal>${param}</literal>.</para> </sect1> - <sect1 id="shell-programming-quoting"> + <sect1 xml:id="shell-programming-quoting"> <title>Quoting</title> <para>Le stringhe possono essere quotate per controllare il modo in cui la @@ -189,7 +188,7 @@ Wed</screen> {bat}man</screen> </sect1> - <sect1 id="shell-programming-var"> + <sect1 xml:id="shell-programming-var"> <title>Variabili</title> <para>Alcune variabili sono automaticamente inizializzate all'avvio della @@ -198,7 +197,7 @@ Wed</screen> <para>Queste <emphasis>variabili di shell</emphasis> sono:</para> - <table frame="all" id="shell-programming-table-shell-var"> + <table frame="all" xml:id="shell-programming-table-shell-var"> <title>Variabili di shell</title> <tgroup cols="4"> @@ -230,7 +229,7 @@ Wed</screen> <entry align="center">x</entry> - <entry align="center"></entry> + <entry align="center"/> </row> <row> @@ -240,7 +239,7 @@ Wed</screen> <entry align="center">x</entry> - <entry align="center"></entry> + <entry align="center"/> </row> <row> @@ -250,7 +249,7 @@ Wed</screen> <entry align="center">x</entry> - <entry align="center"></entry> + <entry align="center"/> </row> <row> @@ -271,11 +270,11 @@ Wed</screen> <entry align="center">x</entry> - <entry align="center"></entry> + <entry align="center"/> </row> <row> - <entry><literal>$<replaceable>n</replaceable></literal></entry> + <entry><literal>$n</literal></entry> <entry>argomento su linea di comando, dove <replaceable>n</replaceable> varia tra 1 e 9, leggendo da sinistra @@ -315,26 +314,26 @@ Wed</screen> <entry align="center">x</entry> - <entry align="center"></entry> + <entry align="center"/> </row> <row> - <entry><literal>$argv[<replaceable>n</replaceable>]</literal></entry> + <entry><literal>$argv[n]</literal></entry> <entry>seleziona l'<replaceable>n-esima</replaceable> parola dalla lista di input</entry> - <entry align="center"></entry> + <entry align="center"/> <entry align="center">x</entry> </row> <row> - <entry><literal>${argv[<replaceable>n</replaceable>]}</literal></entry> + <entry><literal>${argv[n]}</literal></entry> <entry>come sopra</entry> - <entry align="center"></entry> + <entry align="center"/> <entry align="center">x</entry> </row> @@ -344,7 +343,7 @@ Wed</screen> <entry>riporta il numero di parole della lista di input</entry> - <entry align="center"></entry> + <entry align="center"/> <entry align="center">x</entry> </row> @@ -414,7 +413,7 @@ ${argv[4]}: four $#argv: 5</screen> </sect1> - <sect1 id="shell-programming-param-sost"> + <sect1 xml:id="shell-programming-param-sost"> <title>Sostituzione di parametri</title> <para>Si può riferirsi ai parametri in modo astratto e sostituire i @@ -428,28 +427,28 @@ $#argv: 5</screen> <tbody> <row> - <entry><literal>$<replaceable>parametro</replaceable></literal></entry> + <entry><literal>$parametro</literal></entry> <entry>sostituisce questa stringa con il valore di <replaceable>parametro</replaceable></entry> </row> <row> - <entry><literal>${<replaceable>parametro</replaceable>}</literal></entry> + <entry><literal>${parametro}</literal></entry> <entry>come sopra. Le parentesi sono d'aiuto se non c'è separazione tra questo parametro e una stringa adiacente.</entry> </row> <row> - <entry><literal>$<replaceable>parametro</replaceable>=</literal></entry> + <entry><literal>$parametro=</literal></entry> <entry>setta <replaceable>parametro</replaceable> a <emphasis>null</emphasis>.</entry> </row> <row> - <entry><literal>${<replaceable>parametro</replaceable>-<replaceable>default</replaceable>}</literal></entry> + <entry><literal>${parametro-default}</literal></entry> <entry>se <replaceable>parametro</replaceable> non è settato allora si usa <replaceable>default</replaceable> come valore. @@ -457,7 +456,7 @@ $#argv: 5</screen> </row> <row> - <entry><literal>${<replaceable>parametro</replaceable>=<replaceable>default</replaceable>}</literal></entry> + <entry><literal>${parametro=default}</literal></entry> <entry>se <replaceable>parametro</replaceable> non è settato allora lo si setta a <replaceable>default</replaceable> e si usa @@ -465,7 +464,7 @@ $#argv: 5</screen> </row> <row> - <entry><literal>${<replaceable>parametro</replaceable>+<replaceable>nuovo_valore</replaceable>}</literal></entry> + <entry><literal>${parametro+nuovo_valore}</literal></entry> <entry>se <replaceable>parametro</replaceable> è settato allora si usa <replaceable>nuovo_valore</replaceable> altrimenti @@ -474,7 +473,7 @@ $#argv: 5</screen> </row> <row> - <entry><literal>${<replaceable>parametro</replaceable>?<replaceable>messaggio</replaceable>}</literal></entry> + <entry><literal>${parametro?messaggio}</literal></entry> <entry>se <replaceable>parametro</replaceable> non è settato allora si visualizza il messaggio. Se @@ -498,14 +497,14 @@ $#argv: 5</screen> <tbody> <row> - <entry><literal>$lista[<replaceable>n</replaceable>]</literal></entry> + <entry><literal>$lista[n]</literal></entry> <entry>seleziona l'<replaceable>n-esima</replaceable> parola dalla lista</entry> </row> <row> - <entry><literal>${lista[<replaceable>n</replaceable>]}</literal></entry> + <entry><literal>${lista[n]}</literal></entry> <entry>come sopra</entry> </row> @@ -517,14 +516,14 @@ $#argv: 5</screen> </row> <row> - <entry><literal>$?<replaceable>parametro</replaceable></literal></entry> + <entry><literal>$?parametro</literal></entry> <entry>ritorna 1 se il parametro è settato, 0 altrimenti</entry> </row> <row> - <entry><literal>${?<replaceable>parametro</replaceable>}</literal></entry> + <entry><literal>${?parametro}</literal></entry> <entry>come sopra</entry> </row> @@ -539,7 +538,7 @@ $#argv: 5</screen> </informaltable> <para>Inoltre la shell C definisce l'array - <literal>$argv[<replaceable>n</replaceable>]</literal> per + <literal>$argv[n]</literal> per contenere gli <replaceable>n</replaceable> argomenti della linea di comando e <literal>$#argv</literal> per il numero di argomenti, come specificato in <link linkend="shell-programming-table-shell-var">Tabella @@ -581,7 +580,7 @@ echo "3: ${param3+3}: \c" ;echo $param3</programlisting> 3: 3: three # sostituisce 3 ma non assegna questo valore</screen> </sect1> - <sect1 id="shell-programming-here-doc"> + <sect1 xml:id="shell-programming-here-doc"> <title>Here document</title> <para>Un <emphasis>here document</emphasis> è una forma di quoting @@ -644,13 +643,13 @@ sostituzione di variabile</screen> semplici stringhe di testo senza effettuare la sostituzione.</para> </sect1> - <sect1 id="shell-programming-int-input"> + <sect1 xml:id="shell-programming-int-input"> <title>Input interattivo</title> <para>Gli script di shell possono accettare input interattivo per inizializzare parametri all'interno dello script stesso.</para> - <sect2 id="shell-programming-int-input-sh"> + <sect2 xml:id="shell-programming-int-input-sh"> <title>Sh</title> <para>&man.sh.1; utilizza il comando built-in <command>read</command> per @@ -674,7 +673,7 @@ echo param=$param</programlisting> param=hello frank</screen> </sect2> - <sect2 id="shell-programming-int-input-csh"> + <sect2 xml:id="shell-programming-int-input-csh"> <title>Csh</title> <para>&man.csh.1; usa il simbolo <literal>$<</literal> per leggere una @@ -699,15 +698,15 @@ param=hello frank</screen> </sect2> </sect1> - <sect1 id="shell-programming-functions"> + <sect1 xml:id="shell-programming-functions"> <title>Funzioni</title> <para>La shell Bourne permette di definire funzioni. Queste sono molto simili agli alias della shell C, ma permettono più flessibilità. Una funzione ha la forma:</para> - <para><command><replaceable>funzione</replaceable> () { - <replaceable>comando</replaceable>; }</command></para> + <para><command>funzione () { + comando; }</command></para> <para>dove lo spazio dopo { e il punto e virgola (;) sono obbligatori; il punto e virgola può essere omesso facendo precedere a } un @@ -814,16 +813,16 @@ $Offline</programlisting> sopra.</para> </sect1> - <sect1 id="shell-programming-control-comm"> + <sect1 xml:id="shell-programming-control-comm"> <title>Comandi di controllo</title> - <sect2 id="shell-programming-control-comm-if"> + <sect2 xml:id="shell-programming-control-comm-if"> <title>Condizionale if</title> <para>L'espressione condizionale <command>if</command> è disponibile in entrambe le shell, ma con una diversa sintassi.</para> - <sect3 id="shell-programming-control-comm-if-sh"> + <sect3 xml:id="shell-programming-control-comm-if-sh"> <title>Sh</title> <programlisting><command>if</command> <replaceable>condizione1</replaceable> @@ -836,8 +835,7 @@ $Offline</programlisting> <command>fi</command></programlisting> <para>Le condizioni sono sottoposte usualmente al comando &man.test.1; o - <command>[]</command> (Vedere la <link - linkend="shell-programming-control-comm-test">sezione 9.9.6</link>). + <command>[]</command> (Vedere la <link linkend="shell-programming-control-comm-test">sezione 9.9.6</link>). L'<command>if</command> e <command>then</command> devono essere separati con un newline o un punto e virgola (;).</para> @@ -871,10 +869,10 @@ one</screen> two</screen> </sect3> - <sect3 id="shell-programming-control-comm-if-csh"> + <sect3 xml:id="shell-programming-control-comm-if-csh"> <title>Csh</title> - <programlisting><command>if</command> (<replaceable>condizione</replaceable>) <command><replaceable>comando</replaceable></command> + <programlisting><command>if</command> (<replaceable>condizione</replaceable>) <command>comando</command> -oppure- <command>if</command> (<replaceable>condizione1</replaceable>) <command>then</command> lista di comandi se <replaceable>condizione1</replaceable> è vera (true) @@ -888,7 +886,7 @@ two</screen> sulla stessa linea.</para> <programlisting>#!/bin/csh -f -if ( $#argv >= 2 ) then +if ( $#argv >= 2 ) then echo $2 else if ( $#argv == 1 ) then echo $1 @@ -915,14 +913,14 @@ two</screen> </sect3> </sect2> - <sect2 id="shell-programming-control-comm-switch-case"> + <sect2 xml:id="shell-programming-control-comm-switch-case"> <title>Condizionale switch e case</title> <para>Per scegliere tra una serie di valori di tipo stringa relativi a un parametro si usa <command>case</command> nella shell Bourne e <command>switch</command> nella shell C.</para> - <sect3 id="shell-programming-control-comm-switch-case-sh"> + <sect3 xml:id="shell-programming-control-comm-switch-case-sh"> <title>Sh</title> <programlisting><command>case</command> <replaceable>parametro</replaceable> <command>in</command> @@ -1017,7 +1015,7 @@ esac</programlisting> </informaltable> </sect3> - <sect3 id="shell-programming-control-comm-switch-case-csh"> + <sect3 xml:id="shell-programming-control-comm-switch-case-csh"> <title>Csh</title> <programlisting><command>switch</command> (<replaceable>parametro</replaceable>) @@ -1060,14 +1058,14 @@ endsw</programlisting> </sect3> </sect2> - <sect2 id="shell-programming-control-comm-for-foreach"> + <sect2 xml:id="shell-programming-control-comm-for-foreach"> <title>for e foreach</title> <para>Per effettuare un ciclo tra una lista di valori di tipo stringa si possono usare i comandi <command>for</command> e <command>foreach</command>.</para> - <sect3 id="shell-programming-control-comm-for-foreach-sh"> + <sect3 xml:id="shell-programming-control-comm-for-foreach-sh"> <title>Sh</title> <programlisting><command>for</command> <replaceable>variabile</replaceable> [<command>in</command> <replaceable>lista_di_valori</replaceable>] @@ -1095,7 +1093,7 @@ do done</programlisting> </sect3> - <sect3 id="shell-programming-control-comm-for-foreach-csh"> + <sect3 xml:id="shell-programming-control-comm-for-foreach-csh"> <title>Csh</title> <programlisting><command>foreach</command> <replaceable>variabile</replaceable> (<replaceable>lista_di_valori</replaceable>) @@ -1114,13 +1112,13 @@ end</programlisting> </sect3> </sect2> - <sect2 id="shell-programming-control-comm-while"> + <sect2 xml:id="shell-programming-control-comm-while"> <title>while</title> <para>Il comando <command>while</command> permette di effettuare il ciclo sempre che la condizione sia vera.</para> - <sect3 id="shell-programming-control-comm-while-sh"> + <sect3 xml:id="shell-programming-control-comm-while-sh"> <title>Sh</title> <programlisting><command>while</command> <replaceable>condizione</replaceable> @@ -1151,7 +1149,7 @@ two three</screen> </sect3> - <sect3 id="shell-programming-control-comm-while-csh"> + <sect3 xml:id="shell-programming-control-comm-while-csh"> <title>Csh</title> <programlisting><command>while</command> (<replaceable>condizione</replaceable>) @@ -1174,7 +1172,7 @@ end</programlisting> </sect3> </sect2> - <sect2 id="shell-programming-control-comm-until"> + <sect2 xml:id="shell-programming-control-comm-until"> <title>until</title> <para>Questo costrutto di ciclo è solamente disponibile per la @@ -1209,7 +1207,7 @@ done</programlisting> dell'esecuzione dei comandi.</para> </sect2> - <sect2 id="shell-programming-control-comm-test"> + <sect2 xml:id="shell-programming-control-comm-test"> <title>test</title> <para>Le espressioni condizionali vengono valutate per valori @@ -1494,7 +1492,7 @@ done</programlisting> </informaltable> </sect2> - <sect2 id="shell-programming-control-comm-csh-log-rel-op"> + <sect2 xml:id="shell-programming-control-comm-csh-log-rel-op"> <title>Operatori relazionali e logici della shell C</title> <para>La shell C possiede un suo set di operatori logici e relazionali @@ -1620,7 +1618,7 @@ done</programlisting> </row> <row> - <entry><command>{<replaceable>comando</replaceable>}</command></entry> + <entry><command>{comando}</command></entry> <entry>vero (1) se il comando termina con uno stato di uscita 0, falso (0) altrimenti.</entry> |