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

📄 sample-bashrc.html

📁 Shall高级编程
💻 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.76b+"><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"><TABLESUMMARY="Header navigation table"WIDTH="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"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="dosbatch.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="APPENDIX"><H1><ANAME="SAMPLE-BASHRC"></A>Appendix K. A Sample <TTCLASS="FILENAME">.bashrc</TT> File</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) ||  62&nbsp;          ${XSERVER} == "unix" ]]; then  63&nbsp;	DISPLAY=":0.0"		# Display on local host  64&nbsp;    else		  65&nbsp;	DISPLAY=${XSERVER}:0.0	# Display on remote host  66&nbsp;    fi  67&nbsp;fi  68&nbsp;  69&nbsp;export DISPLAY  70&nbsp;  71&nbsp;#---------------  72&nbsp;# Some settings  73&nbsp;#---------------  74&nbsp;  75&nbsp;ulimit -S -c 0        # Don't want any coredumps  76&nbsp;set -o notify  77&nbsp;set -o noclobber  78&nbsp;set -o ignoreeof  79&nbsp;set -o nounset  80&nbsp;#set -o xtrace        # Useful for debuging  81&nbsp;  82&nbsp;# Enable options:  83&nbsp;shopt -s cdspell  84&nbsp;shopt -s cdable_vars  85&nbsp;shopt -s checkhash  86&nbsp;shopt -s checkwinsize  87&nbsp;shopt -s mailwarn  88&nbsp;shopt -s sourcepath  89&nbsp;shopt -s no_empty_cmd_completion  # bash&#62;=2.04 only  90&nbsp;shopt -s cmdhist  91&nbsp;shopt -s histappend histreedit histverify  92&nbsp;shopt -s extglob      # Necessary for programmable completion  93&nbsp;  94&nbsp;# Disable options:  95&nbsp;shopt -u mailwarn  96&nbsp;unset MAILCHECK       # I don't want my shell to warn me of incoming mail  97&nbsp;  98&nbsp;  99&nbsp;export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n' 100&nbsp;export HISTIGNORE="&#38;:bg:fg:ll:h" 101&nbsp;export HOSTFILE=$HOME/.hosts	# Put a list of remote hosts in ~/.hosts 102&nbsp; 103&nbsp; 104&nbsp; 105&nbsp;#----------------------- 106&nbsp;# Greeting, motd etc... 107&nbsp;#----------------------- 108&nbsp; 109&nbsp;# Define some colors first: 110&nbsp;red='\e[0;31m' 111&nbsp;RED='\e[1;31m' 112&nbsp;blue='\e[0;34m' 113&nbsp;BLUE='\e[1;34m' 114&nbsp;cyan='\e[0;36m' 115&nbsp;CYAN='\e[1;36m' 116&nbsp;NC='\e[0m'              # No Color 117&nbsp;# --&#62; Nice. Has the same effect as using "ansi.sys" in DOS. 118&nbsp; 119&nbsp;# Looks best on a black background..... 120&nbsp;echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}\ 121&nbsp;${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n" 122&nbsp;date 123&nbsp;if [ -x /usr/games/fortune ]; then 124&nbsp;    /usr/games/fortune -s     # makes our day a bit more fun.... :-) 125&nbsp;fi 126&nbsp; 127&nbsp;function _exit()	# function to run upon exit of shell 128&nbsp;{ 129&nbsp;    echo -e "${RED}Hasta la vista, baby${NC}" 130&nbsp;} 131&nbsp;trap _exit EXIT 132&nbsp; 133&nbsp;#--------------- 134&nbsp;# Shell Prompt 135&nbsp;#--------------- 136&nbsp; 137&nbsp;if [[ "${DISPLAY#$HOST}" != ":0.0" &#38;&#38;  "${DISPLAY}" != ":0" ]]; then   138&nbsp;    HILIT=${red}   # remote machine: prompt will be partly red 139&nbsp;else 140&nbsp;    HILIT=${cyan}  # local machine: prompt will be partly cyan 141&nbsp;fi 142&nbsp; 143&nbsp;#  --&#62; Replace instances of \W with \w in prompt functions below 144&nbsp;#+ --&#62; to get display of full path name. 145&nbsp; 146&nbsp;function fastprompt() 147&nbsp;{ 148&nbsp;    unset PROMPT_COMMAND 149&nbsp;    case $TERM in 150&nbsp;        *term | rxvt ) 151&nbsp;           PS1="${HILIT}[\h]$NC \W &#62; \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; 152&nbsp;	linux ) 153&nbsp;           PS1="${HILIT}[\h]$NC \W &#62; " ;; 154&nbsp;        *) 155&nbsp;           PS1="[\h] \W &#62; " ;; 156&nbsp;    esac 157&nbsp;} 158&nbsp; 159&nbsp;function powerprompt() 160&nbsp;{ 161&nbsp;    _powerprompt() 162&nbsp;    { 163&nbsp;        LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g") 164&nbsp;    } 165&nbsp; 166&nbsp; PROMPT_COMMAND=_powerprompt 167&nbsp; case $TERM in 168&nbsp;   *term | rxvt  ) 169&nbsp;      PS1="${HILIT}[\A \$LOAD]$NC\n[\h \#] \W &#62; \ 170&nbsp;           \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; 171&nbsp;        linux ) 172&nbsp;           PS1="${HILIT}[\A - \$LOAD]$NC\n[\h \#] \w &#62; " ;; 173&nbsp;        * ) 174&nbsp;           PS1="[\A - \$LOAD]\n[\h \#] \w &#62; " ;; 175&nbsp; esac 176&nbsp;} 177&nbsp; 178&nbsp;powerprompt     # This is the default prompt -- might be slow. 179&nbsp;                # If too slow, use fastprompt instead. 180&nbsp; 181&nbsp;#=============================================================== 182&nbsp;# 183&nbsp;# ALIASES AND FUNCTIONS 184&nbsp;# 185&nbsp;# Arguably, some functions defined here are quite big 186&nbsp;# (ie 'lowercase') but my workstation has 512Meg of RAM, so ... 187&nbsp;# If you want to make this file smaller, these functions can 188&nbsp;# be converted into scripts. 189&nbsp;# 190&nbsp;# Many functions were taken (almost) straight from the bash-2.04 191&nbsp;# examples. 192&nbsp;# 193&nbsp;#=============================================================== 194&nbsp; 195&nbsp;#------------------- 196&nbsp;# Personnal Aliases 197&nbsp;#------------------- 198&nbsp; 199&nbsp;alias rm='rm -i' 200&nbsp;alias cp='cp -i' 201&nbsp;alias mv='mv -i' 202&nbsp;# -&#62; Prevents accidentally clobbering files. 203&nbsp;alias mkdir='mkdir -p' 204&nbsp; 205&nbsp;alias h='history' 206&nbsp;alias j='jobs -l' 207&nbsp;alias r='rlogin' 208&nbsp;alias which='type -all' 209&nbsp;alias ..='cd ..' 210&nbsp;alias path='echo -e ${PATH//:/\\n}' 211&nbsp;alias print='/usr/bin/lp -o nobanner -d $LPDEST' 212&nbsp;      # Assumes LPDEST is defined 213&nbsp;alias pjet='enscript -h -G -fCourier9 -d $LPDEST' 214&nbsp;      # Pretty-print using enscript 215&nbsp;alias background='xv -root -quit -max -rmode 5' 216&nbsp;      # Put a picture in the background 217&nbsp;alias du='du -kh' 218&nbsp;alias df='df -kTh' 219&nbsp; 220&nbsp;# The 'ls' family (this assumes you use the GNU ls) 221&nbsp;alias la='ls -Al'               # show hidden files 222&nbsp;alias ls='ls -hF --color'	# add colors for filetype recognition 223&nbsp;alias lx='ls -lXB'              # sort by extension 224&nbsp;alias lk='ls -lSr'              # sort by size 225&nbsp;alias lc='ls -lcr'		# sort by change time   226&nbsp;alias lu='ls -lur'		# sort by access time    227&nbsp;alias lr='ls -lR'               # recursive ls 228&nbsp;alias lt='ls -ltr'              # sort by date 229&nbsp;alias lm='ls -al |more'         # pipe through 'more' 230&nbsp;alias tree='tree -Csu'		# nice alternative to 'ls' 231&nbsp; 232&nbsp;# tailoring 'less' 233&nbsp;alias more='less' 234&nbsp;export PAGER=less 235&nbsp;export LESSCHARSET='latin1' 236&nbsp;export LESSOPEN='|/usr/bin/lesspipe.sh %s 2&#62;&#38;-' 237&nbsp;       # Use this if lesspipe.sh exists. 238&nbsp;export LESS='-i -N -w  -z-4 -g -e -M -X -F -R -P%t?f%f \ 239&nbsp;:stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...' 240&nbsp; 241&nbsp;# spelling typos - highly personnal :-) 242&nbsp;alias xs='cd' 243&nbsp;alias vf='cd' 244&nbsp;alias moer='more' 245&nbsp;alias moew='more' 246&nbsp;alias kk='ll' 247&nbsp; 248&nbsp;#---------------- 249&nbsp;# a few fun ones 250&nbsp;#---------------- 251&nbsp; 252&nbsp;function xtitle () 253&nbsp;{ 254&nbsp;    case "$TERM" in 255&nbsp;        *term | rxvt) 256&nbsp;            echo -n -e "\033]0;$*\007" ;; 257&nbsp;        *)   258&nbsp;	    ;; 259&nbsp;    esac 260&nbsp;} 261&nbsp; 262&nbsp;# aliases... 263&nbsp;alias top='xtitle Processes on $HOST &#38;&#38; top' 264&nbsp;alias make='xtitle Making $(basename $PWD) ; make' 265&nbsp;alias ncftp="xtitle ncFTP ; ncftp" 266&nbsp; 267&nbsp;# .. and functions 268&nbsp;function man () 269&nbsp;{ 270&nbsp;    for i ; do 271&nbsp;	xtitle The $(basename $1|tr -d .[:digit:]) manual 272&nbsp;	command man -F -a "$i" 273&nbsp;    done 274&nbsp;} 275&nbsp; 276&nbsp;function ll() 277&nbsp;{ ls -l "$@"| egrep "^d" ; ls -lXB "$@" 2&#62;&#38;-| egrep -v "^d|total "; } 278&nbsp; 279&nbsp;function te()  # wrapper around xemacs/gnuserv 280&nbsp;{ 281&nbsp;    if [ "$(gnuclient -batch -eval t 2&#62;&#38;-)" == "t" ]; then 282&nbsp;        gnuclient -q "$@"; 283&nbsp;    else 284&nbsp;        ( xemacs "$@" &#38;); 285&nbsp;    fi 286&nbsp;} 287&nbsp; 288&nbsp;#----------------------------------- 289&nbsp;# File &#38; strings related functions: 290&nbsp;#----------------------------------- 291&nbsp; 292&nbsp;# Find a file with a pattern in name: 293&nbsp;function ff() 294&nbsp; 295&nbsp;{ find . -type f -iname '*'$*'*' -ls ; } 296&nbsp;# Find a file with pattern $1 in name and Execute $2 on it: 297&nbsp; 298&nbsp;function fe()

⌨️ 快捷键说明

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