⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample-bashrc.html

📁 一本完整的描述Unix Shell 编程的工具书的所有范例
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><HTML><HEAD><TITLE>A Sample .bashrc File</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.57"><LINKREL="HOME"TITLE="Advanced Bash-Scripting Guide"HREF="index.html"><LINKREL="PREVIOUS"TITLE="History Commands"HREF="histcommands.html"><LINKREL="NEXT"TITLE="Converting DOS Batch Files to Shell Scripts"HREF="dosbatch.html"><METAHTTP-EQUIV="Content-Style-Type"CONTENT="text/css"><LINKREL="stylesheet"HREF="common/kde-common.css"TYPE="text/css"><METAHTTP-EQUIV="Content-Type"CONTENT="text/html; charset=iso-8859-1"><METAHTTP-EQUIV="Content-Language"CONTENT="en"><LINKREL="stylesheet"HREF="common/kde-localised.css"TYPE="text/css"TITLE="KDE-English"><LINKREL="stylesheet"HREF="common/kde-default.css"TYPE="text/css"TITLE="KDE-Default"></HEAD><BODYCLASS="APPENDIX"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#AA0000"VLINK="#AA0055"ALINK="#AA0000"STYLE="font-family: sans-serif;"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="histcommands.html">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="dosbatch.html">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="APPENDIX"><H1><ANAME="SAMPLE-BASHRC">Appendix K. A Sample <TTCLASS="FILENAME">.bashrc</TT> File</A></H1><P>The <TTCLASS="FILENAME">~/.bashrc</TT> file determines the       behavior of interactive shells. A good look at this file can       lead to a better understanding of Bash.</P><P><AHREF="mailto:emmanuel.rouat@wanadoo.fr"TARGET="_top">Emmanuel        Rouat</A> contributed the following very elaborate        <TTCLASS="FILENAME">.bashrc</TT> file, written for a Linux system.        He welcomes reader feedback on it.</P><P>Study the file carefully, and feel free to reuse code        snippets and functions from it in your own        <TTCLASS="FILENAME">.bashrc</TT> file or even in your scripts.</P><DIVCLASS="EXAMPLE"><HR><ANAME="BASHRC"></A><P><B>Example K-1. Sample <TTCLASS="FILENAME">.bashrc</TT> file</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#===============================================================   2&nbsp;#   3&nbsp;# PERSONAL $HOME/.bashrc FILE for bash-2.05a (or later)   4&nbsp;#   5&nbsp;# Last modified: Tue Apr 15 20:32:34 CEST 2003   6&nbsp;#   7&nbsp;# This file is read (normally) by interactive shells only.   8&nbsp;# Here is the place to define your aliases, functions and   9&nbsp;# other interactive features like your prompt.  10&nbsp;#  11&nbsp;# This file was designed (originally) for Solaris but based   12&nbsp;# on Redhat's default .bashrc file  13&nbsp;# --&#62; Modified for Linux.  14&nbsp;# The majority of the code you'll find here is based on code found  15&nbsp;# on Usenet (or internet).  16&nbsp;# This bashrc file is a bit overcrowded - remember it is just  17&nbsp;# just an example. Tailor it to your needs  18&nbsp;#  19&nbsp;#  20&nbsp;#===============================================================  21&nbsp;  22&nbsp;# --&#62; Comments added by HOWTO author.  23&nbsp;# --&#62; And then edited again by ER :-)  24&nbsp;  25&nbsp;#-----------------------------------  26&nbsp;# Source global definitions (if any)  27&nbsp;#-----------------------------------  28&nbsp;  29&nbsp;if [ -f /etc/bashrc ]; then  30&nbsp;        . /etc/bashrc   # --&#62; Read /etc/bashrc, if present.  31&nbsp;fi  32&nbsp;  33&nbsp;#-------------------------------------------------------------  34&nbsp;# Automatic setting of $DISPLAY (if not set already)  35&nbsp;# This works for linux - your mileage may vary....   36&nbsp;# The problem is that different types of terminals give  37&nbsp;# different answers to 'who am i'......  38&nbsp;# I have not found a 'universal' method yet  39&nbsp;#-------------------------------------------------------------  40&nbsp;  41&nbsp;function get_xserver ()  42&nbsp;{  43&nbsp;    case $TERM in  44&nbsp;	xterm )  45&nbsp;            XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' )   46&nbsp;            # Ane-Pieter Wieringa suggests the following alternative:  47&nbsp;            # I_AM=$(who am i)  48&nbsp;            # SERVER=${I_AM#*(}  49&nbsp;            # SERVER=${SERVER%*)}  50&nbsp;  51&nbsp;            XSERVER=${XSERVER%%:*}  52&nbsp;	    ;;  53&nbsp;	aterm | rxvt)  54&nbsp; 	# find some code that works here.....  55&nbsp;	    ;;  56&nbsp;    esac    57&nbsp;}  58&nbsp;  59&nbsp;if [ -z ${DISPLAY:=""} ]; then  60&nbsp;    get_xserver  61&nbsp;    if [[ -z ${XSERVER}  || ${XSERVER} == $(hostname) || ${XSERVER} == "unix" ]]; then   62&nbsp;	DISPLAY=":0.0"		# Display on local host  63&nbsp;    else		  64&nbsp;	DISPLAY=${XSERVER}:0.0	# Display on remote host  65&nbsp;    fi  66&nbsp;fi  67&nbsp;  68&nbsp;export DISPLAY  69&nbsp;  70&nbsp;#---------------  71&nbsp;# Some settings  72&nbsp;#---------------  73&nbsp;  74&nbsp;ulimit -S -c 0		# Don't want any coredumps  75&nbsp;set -o notify  76&nbsp;set -o noclobber  77&nbsp;set -o ignoreeof  78&nbsp;set -o nounset  79&nbsp;#set -o xtrace          # useful for debuging  80&nbsp;  81&nbsp;# Enable options:  82&nbsp;shopt -s cdspell  83&nbsp;shopt -s cdable_vars  84&nbsp;shopt -s checkhash  85&nbsp;shopt -s checkwinsize  86&nbsp;shopt -s mailwarn  87&nbsp;shopt -s sourcepath  88&nbsp;shopt -s no_empty_cmd_completion  # bash&#62;=2.04 only  89&nbsp;shopt -s cmdhist  90&nbsp;shopt -s histappend histreedit histverify  91&nbsp;shopt -s extglob	# necessary for programmable completion  92&nbsp;  93&nbsp;# Disable options:  94&nbsp;shopt -u mailwarn  95&nbsp;unset MAILCHECK		# I don't want my shell to warn me of incoming mail  96&nbsp;  97&nbsp;  98&nbsp;export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n'  99&nbsp;export HISTIGNORE="&#38;:bg:fg:ll:h" 100&nbsp;export HOSTFILE=$HOME/.hosts	# Put a list of remote hosts in ~/.hosts 101&nbsp; 102&nbsp; 103&nbsp; 104&nbsp;#----------------------- 105&nbsp;# Greeting, motd etc... 106&nbsp;#----------------------- 107&nbsp; 108&nbsp;# Define some colors first: 109&nbsp;red='\e[0;31m' 110&nbsp;RED='\e[1;31m' 111&nbsp;blue='\e[0;34m' 112&nbsp;BLUE='\e[1;34m' 113&nbsp;cyan='\e[0;36m' 114&nbsp;CYAN='\e[1;36m' 115&nbsp;NC='\e[0m'              # No Color 116&nbsp;# --&#62; Nice. Has the same effect as using "ansi.sys" in DOS. 117&nbsp; 118&nbsp;# Looks best on a black background..... 119&nbsp;echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n" 120&nbsp;date 121&nbsp;if [ -x /usr/games/fortune ]; then 122&nbsp;    /usr/games/fortune -s     # makes our day a bit more fun.... :-) 123&nbsp;fi 124&nbsp; 125&nbsp;function _exit()	# function to run upon exit of shell 126&nbsp;{ 127&nbsp;    echo -e "${RED}Hasta la vista, baby${NC}" 128&nbsp;} 129&nbsp;trap _exit EXIT 130&nbsp; 131&nbsp;#--------------- 132&nbsp;# Shell Prompt 133&nbsp;#--------------- 134&nbsp; 135&nbsp;if [[ "${DISPLAY#$HOST}" != ":0.0" &#38;&#38;  "${DISPLAY}" != ":0" ]]; then   136&nbsp;    HILIT=${red}   # remote machine: prompt will be partly red 137&nbsp;else 138&nbsp;    HILIT=${cyan}  # local machine: prompt will be partly cyan 139&nbsp;fi 140&nbsp; 141&nbsp;#  --&#62; Replace instances of \W with \w in prompt functions below 142&nbsp;#+ --&#62; to get display of full path name. 143&nbsp; 144&nbsp;function fastprompt() 145&nbsp;{ 146&nbsp;    unset PROMPT_COMMAND 147&nbsp;    case $TERM in 148&nbsp;        *term | rxvt ) 149&nbsp;            PS1="${HILIT}[\h]$NC \W &#62; \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; 150&nbsp;	linux ) 151&nbsp;	    PS1="${HILIT}[\h]$NC \W &#62; " ;; 152&nbsp;        *) 153&nbsp;            PS1="[\h] \W &#62; " ;; 154&nbsp;    esac 155&nbsp;} 156&nbsp; 157&nbsp;function powerprompt() 158&nbsp;{ 159&nbsp;    _powerprompt() 160&nbsp;    { 161&nbsp;        LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g") 162&nbsp;    } 163&nbsp; 164&nbsp;    PROMPT_COMMAND=_powerprompt 165&nbsp;    case $TERM in 166&nbsp;        *term | rxvt  ) 167&nbsp;            PS1="${HILIT}[\A \$LOAD]$NC\n[\h \#] \W &#62; \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; 168&nbsp;        linux ) 169&nbsp;            PS1="${HILIT}[\A - \$LOAD]$NC\n[\h \#] \w &#62; " ;; 170&nbsp;        * ) 171&nbsp;            PS1="[\A - \$LOAD]\n[\h \#] \w &#62; " ;; 172&nbsp;    esac 173&nbsp;} 174&nbsp; 175&nbsp;powerprompt     # this is the default prompt - might be slow 176&nbsp;                # If too slow, use fastprompt instead.... 177&nbsp; 178&nbsp;#=============================================================== 179&nbsp;# 180&nbsp;# ALIASES AND FUNCTIONS 181&nbsp;# 182&nbsp;# Arguably, some functions defined here are quite big 183&nbsp;# (ie 'lowercase') but my workstation has 512Meg of RAM, so ..... 184&nbsp;# If you want to make this file smaller, these functions can 185&nbsp;# be converted into scripts. 186&nbsp;# 187&nbsp;# Many functions were taken (almost) straight from the bash-2.04 188&nbsp;# examples. 189&nbsp;# 190&nbsp;#=============================================================== 191&nbsp; 192&nbsp;#------------------- 193&nbsp;# Personnal Aliases 194&nbsp;#------------------- 195&nbsp; 196&nbsp;alias rm='rm -i' 197&nbsp;alias cp='cp -i' 198&nbsp;alias mv='mv -i' 199&nbsp;# -&#62; Prevents accidentally clobbering files. 200&nbsp;alias mkdir='mkdir -p' 201&nbsp; 202&nbsp;alias h='history' 203&nbsp;alias j='jobs -l' 204&nbsp;alias r='rlogin' 205&nbsp;alias which='type -all' 206&nbsp;alias ..='cd ..' 207&nbsp;alias path='echo -e ${PATH//:/\\n}' 208&nbsp;alias print='/usr/bin/lp -o nobanner -d $LPDEST'   # Assumes LPDEST is defined 209&nbsp;alias pjet='enscript -h -G -fCourier9 -d $LPDEST'  # Pretty-print using enscript 210&nbsp;alias background='xv -root -quit -max -rmode 5'    # Put a picture in the background 211&nbsp;alias du='du -kh' 212&nbsp;alias df='df -kTh' 213&nbsp; 214&nbsp;# The 'ls' family (this assumes you use the GNU ls) 215&nbsp;alias la='ls -Al'               # show hidden files 216&nbsp;alias ls='ls -hF --color'	# add colors for filetype recognition 217&nbsp;alias lx='ls -lXB'              # sort by extension 218&nbsp;alias lk='ls -lSr'              # sort by size 219&nbsp;alias lc='ls -lcr'		# sort by change time   220&nbsp;alias lu='ls -lur'		# sort by access time    221&nbsp;alias lr='ls -lR'               # recursive ls 222&nbsp;alias lt='ls -ltr'              # sort by date 223&nbsp;alias lm='ls -al |more'         # pipe through 'more' 224&nbsp;alias tree='tree -Csu'		# nice alternative to 'ls' 225&nbsp; 226&nbsp;# tailoring 'less' 227&nbsp;alias more='less' 228&nbsp;export PAGER=less 229&nbsp;export LESSCHARSET='latin1' 230&nbsp;export LESSOPEN='|/usr/bin/lesspipe.sh %s 2&#62;&#38;-' # Use this if lesspipe.sh exists 231&nbsp;export LESS='-i -N -w  -z-4 -g -e -M -X -F -R -P%t?f%f \ 232&nbsp;:stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...' 233&nbsp; 234&nbsp;# spelling typos - highly personnal :-) 235&nbsp;alias xs='cd' 236&nbsp;alias vf='cd' 237&nbsp;alias moer='more' 238&nbsp;alias moew='more' 239&nbsp;alias kk='ll' 240&nbsp; 241&nbsp;#---------------- 242&nbsp;# a few fun ones 243&nbsp;#---------------- 244&nbsp; 245&nbsp;function xtitle () 246&nbsp;{ 247&nbsp;    case "$TERM" in 248&nbsp;        *term | rxvt) 249&nbsp;            echo -n -e "\033]0;$*\007" ;; 250&nbsp;        *)   251&nbsp;	    ;; 252&nbsp;    esac 253&nbsp;} 254&nbsp; 255&nbsp;# aliases... 256&nbsp;alias top='xtitle Processes on $HOST &#38;&#38; top' 257&nbsp;alias make='xtitle Making $(basename $PWD) ; make' 258&nbsp;alias ncftp="xtitle ncFTP ; ncftp" 259&nbsp; 260&nbsp;# .. and functions 261&nbsp;function man () 262&nbsp;{ 263&nbsp;    for i ; do 264&nbsp;	xtitle The $(basename $1|tr -d .[:digit:]) manual 265&nbsp;	command man -F -a "$i" 266&nbsp;    done 267&nbsp;} 268&nbsp; 269&nbsp;function ll(){ ls -l "$@"| egrep "^d" ; ls -lXB "$@" 2&#62;&#38;-| egrep -v "^d|total "; } 270&nbsp;function te()  # wrapper around xemacs/gnuserv 271&nbsp;{ 272&nbsp;    if [ "$(gnuclient -batch -eval t 2&#62;&#38;-)" == "t" ]; then 273&nbsp;        gnuclient -q "$@"; 274&nbsp;    else 275&nbsp;        ( xemacs "$@" &#38;); 276&nbsp;    fi 277&nbsp;} 278&nbsp; 279&nbsp;#----------------------------------- 280&nbsp;# File &#38; strings related functions: 281&nbsp;#----------------------------------- 282&nbsp; 283&nbsp;# Find a file with a pattern in name: 284&nbsp;function ff() { find . -type f -iname '*'$*'*' -ls ; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -