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.

newgrp<br />

tty<br />

stty<br />

Capitolo 13. Coman<strong>di</strong> <strong>di</strong> sistema e d’amministrazione<br />

bash$ last reboot<br />

reboot system boot 2.6.9-1.667 Fri Feb 4 18:18 (00:02)<br />

reboot system boot 2.6.9-1.667 Fri Feb 4 15:20 (01:27)<br />

reboot system boot 2.6.9-1.667 Fri Feb 4 12:56 (00:49)<br />

reboot system boot 2.6.9-1.667 Thu Feb 3 21:08 (02:17)<br />

. . .<br />

wtmp begins Tue Feb 1 12:50:09 2005<br />

Mo<strong>di</strong>fica l’ID <strong>di</strong> gruppo dell’utente senza doversi <strong>di</strong>sconnettere. Consente l’accesso ai file <strong>di</strong> un<br />

nuovo gruppo. Poiché gli utenti possono appartenere contemporaneamente a più gruppi, questo<br />

comando viene poco utilizzato.<br />

Terminali<br />

Visualizza il nome del terminale dell’utente corrente. È da notare che ciascuna <strong>di</strong>fferente finestra <strong>di</strong><br />

xterm viene considerata come un <strong>di</strong>verso terminale.<br />

bash$ tty<br />

/dev/pts/1<br />

Mostra e/o mo<strong>di</strong>fica le impostazioni del terminale. Questo complesso comando, usato in uno script,<br />

riesce a controllare il comportamento del terminale e le modalità <strong>di</strong> visualizzazione degli output. Si<br />

veda la sua pagina info e la si stu<strong>di</strong> attentamente.<br />

Esempio 13-2. Abilitare un carattere <strong>di</strong> cancellazione<br />

#!/bin/bash<br />

# erase.sh: Uso <strong>di</strong> "stty" per impostare un carattere <strong>di</strong> cancellazione nella<br />

#+ lettura dell’input.<br />

echo -n "Come ti chiami? "<br />

read nome # Provate ad usare il tasto <strong>di</strong> ritorno<br />

#+ (backspace) per cancellare i caratteri<br />

#+ <strong>di</strong>gitati. Problemi?.<br />

echo "Ti chiami $nome."<br />

stty erase ’#’ # Imposta il carattere "hash" (#) come<br />

#+ carattere <strong>di</strong> cancellazione.<br />

echo -n "Come ti chiami? "<br />

read nome # Usate # per cancellare l’ultimo carattere<br />

#+ <strong>di</strong>gitato.<br />

echo "Ti chiami $nome."<br />

# Attenzione: questa impostazione permane anche dopo l’uscita dallo script.<br />

347

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

Saved successfully!

Ooh no, something went wrong!