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.

shopt -s histappend histree<strong>di</strong>t histverify<br />

shopt -s extglob # necessary for programmable completion<br />

Appen<strong>di</strong>ce K. Un esempio <strong>di</strong> file .bashrc<br />

# Disable options:<br />

shopt -u mailwarn<br />

unset MAILCHECK # I don’t want my shell to warn me of incoming mail<br />

export TIMEFORMAT=$’\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n’<br />

export HISTIGNORE="&:bg:fg:ll:h"<br />

export HOSTFILE=$HOME/.hosts # Put a list of remote hosts in ~/.hosts<br />

#-----------------------<br />

# Greeting, motd etc...<br />

#-----------------------<br />

# Define some colors first:<br />

red=’\e[0;31m’<br />

RED=’\e[1;31m’<br />

blue=’\e[0;34m’<br />

BLUE=’\e[1;34m’<br />

cyan=’\e[0;36m’<br />

CYAN=’\e[1;36m’<br />

NC=’\e[0m’ # No Color<br />

# --> Bello. Ottiene lo stesso effetto dell’impiego <strong>di</strong> "ansi.sys" in DOS.<br />

# Looks best on a black background.....<br />

echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} - DISPLAY on ${RED}$DISPLAY${NC<br />

date<br />

if [ -x /usr/games/fortune ]; then<br />

/usr/games/fortune -s # makes our day a bit more fun.... :-)<br />

fi<br />

function _exit() # function to run upon exit of shell<br />

{<br />

echo -e "${RED}Hasta la vista, baby${NC}"<br />

}<br />

trap _exit EXIT<br />

#---------------<br />

# Shell Prompt<br />

#---------------<br />

if [[ "${DISPLAY#$HOST}" != ":0.0" && "${DISPLAY}" != ":0" ]]; then<br />

HILIT=${red} # remote machine: prompt will be partly red<br />

else<br />

HILIT=${cyan} # local machine: prompt will be partly cyan<br />

fi<br />

# --> Sostituisce le occorrenze <strong>di</strong> \W con \w nelle funzioni <strong>di</strong> prompt seguenti<br />

#+ --> per consentire la visualizzazione completa del percorso.<br />

795

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

Saved successfully!

Ooh no, something went wrong!