informatica:sol:laboratorio15:esercitazionia:bashscriptexamples

Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

Entrambe le parti precedenti la revisioneRevisione precedente
Prossima revisione
Revisione precedente
informatica:sol:laboratorio15:esercitazionia:bashscriptexamples [31/03/2015 alle 09:58 (10 anni fa)] – [removeblanklines.sh] Massimo Torquatiinformatica:sol:laboratorio15:esercitazionia:bashscriptexamples [16/03/2016 alle 11:22 (9 anni fa)] (versione attuale) Massimo Torquati
Linea 12: Linea 12:
 #         Pluto --> PLUTO #         Pluto --> PLUTO
  
-# per ogni argomento +# per ogni argomento  ($@ si può omettere) 
-for f in $@; do    +for f in $@; do        
     # considero solo il nome e non eventuali path che lo precedono     # considero solo il nome e non eventuali path che lo precedono
     bname=`basename $f`     bname=`basename $f`
Linea 90: Linea 90:
 # se non ci sono argomenti stampo il messaggio di usage # se non ci sono argomenti stampo il messaggio di usage
 if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
-    echo "ERRORE: usa: `basename $0` 'file'"+    echo "ERRORE: usa: `basename $0` 'file'" 1>&2
     exit -1     exit -1
 fi fi
 # controllo se il file in ingresso e' un file regolare # controllo se il file in ingresso e' un file regolare
 if [ ! -f $1 ]; then if [ ! -f $1 ]; then
-    echo "ERRORE: il file $1 non esiste o non è un file regolare"+    echo "ERRORE: il file $1 non esiste o non è un file regolare" 1>&2
     exit 1     exit 1
 fi fi
Linea 102: Linea 102:
 r=$(echo $1 | grep "\.[ch]") r=$(echo $1 | grep "\.[ch]")
 if [ "$r" != "$1" ]; then if [ "$r" != "$1" ]; then
-    echo "ERRORE: il file $1 non ha estensione .c o .h"+    echo "ERRORE: il file $1 non ha estensione .c o .h" 1>&2
     exit 2     exit 2
 fi fi
 # controllo l'estensione del file (modo 2: utilizzando le espressioni regolari bash)  # controllo l'estensione del file (modo 2: utilizzando le espressioni regolari bash) 
 if [[ ! $1 =~ .*\.[ch] ]]; then if [[ ! $1 =~ .*\.[ch] ]]; then
-    echo "ERRORE: il file $1 non ha estensione .c o .h"+    echo "ERRORE: il file $1 non ha estensione .c o .h" 1>&2
     exit 2     exit 2
 fi fi
Linea 138: Linea 138:
  
 if [[ $# != 1 ]]; then if [[ $# != 1 ]]; then
-    echo "usa:" +    echo "usa:" 1>&2 
-    echo "  `basename $0` directory"+    echo "  `basename $0` directory" 1>&2
     exit 1     exit 1
 fi fi
  
 if [ ! -d $1 ]; then if [ ! -d $1 ]; then
-    echo "ERROR: $1 non è una directory"+    echo "ERROR: $1 non è una directory" 1>&2
     exit 2     exit 2
 fi fi
 if [ ! -r $1 ]; then if [ ! -r $1 ]; then
-    echo "ERROR: la directory $1 non è leggibile"+    echo "ERROR: la directory $1 non è leggibile" 1>&2
     exit 3     exit 3
 fi fi
informatica/sol/laboratorio15/esercitazionia/bashscriptexamples.1427795908.txt.gz · Ultima modifica: 31/03/2015 alle 09:58 (10 anni fa) da Massimo Torquati

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki