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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appen<strong>di</strong>ce L. Conversione dei file batch <strong>di</strong> DOS<br />

in script <strong>di</strong> shell<br />

Un certo numero <strong>di</strong> programmatori ha imparato lo <strong>scripting</strong> su PC dove era installato il sistema operativo<br />

DOS. Anche il frammentario linguaggio dei file batch <strong>di</strong> DOS consente <strong>di</strong> scrivere delle applicazioni e<br />

degli script piuttosto potenti, anche se questo richiede un ampio impiego <strong>di</strong> espe<strong>di</strong>enti e stratagemmi.<br />

Talvolta, la necessità spinge a convertire vecchi file batch <strong>di</strong> DOS in script <strong>di</strong> shell UNIX. Questa<br />

operazione, generalmente, non è <strong>di</strong>fficile, dal momento che gli operatori dei file batch DOS sono in<br />

numero inferiore rispetto agli analoghi operatori dello <strong>scripting</strong> <strong>di</strong> shell.<br />

Tabella L-1. Parole chiave / variabili / operatori dei file batch e loro equivalenti <strong>di</strong> shell<br />

Operatore <strong>di</strong> File Batch Corrispondente <strong>di</strong> <strong>scripting</strong><br />

<strong>di</strong> shell<br />

Significato<br />

% $ prefisso dei parametri da riga <strong>di</strong><br />

comando<br />

/ - prefisso per le opzione <strong>di</strong> un<br />

comando<br />

\ / separatore <strong>di</strong> percorso<br />

== = (uguale a) verifica <strong>di</strong> confronto <strong>di</strong><br />

stringhe<br />

!==! != (non uguale a) verifica <strong>di</strong><br />

confronto <strong>di</strong> stringhe<br />

| | pipe<br />

@ set +v non visualizza il comando corrente<br />

* * “carattere jolly” per nomi <strong>di</strong> file<br />

> > re<strong>di</strong>rezione <strong>di</strong> file (sovrascrittura)<br />

>> >> re<strong>di</strong>rezione <strong>di</strong> file (accodamento)<br />

< < re<strong>di</strong>rezione dello st<strong>di</strong>n<br />

%VAR% $VAR variabile d’ambiente<br />

REM # commento<br />

NOT ! nega la verifica successiva<br />

NUL /dev/null “buco nero” dove seppellire<br />

l’output dei coman<strong>di</strong><br />

ECHO echo visualizzazione (molte più opzioni<br />

in <strong>Bash</strong>)<br />

ECHO. echo visualizza una riga vuota<br />

ECHO OFF set +v non visualizza il/i comando/i<br />

successivo/i<br />

806

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

Saved successfully!

Ooh no, something went wrong!