bash(1)
要使bash 符合個人的口味,有幾個文檔需要修改:
/etc/bashrc 存有整個系統的別名和功能;
/etc/profile 存有整個系統的環境參數和啟動程式;
$HOME/.bashrc 存有用戶的的別名和功能;
$HOME/.bash_profile 存有用戶的環境參數和啟動程式;
$HOME/.bash_logout 存有退出系統時的結束方式;
$HOME/.inputrc 存有主要綁定數值和其他位元數值;
下文將例舉對這些文檔的修改。首先,最重要的文檔是:/etc/profile。如以下幾節中可以看到,一向以修改這個文檔的方式來設定Linux的各種功能。
--------------------------------------------------------------------------------
# /etc/profile
# System wide environment and startup programs
# --整個系統環境和啟動程式
#
# Functions and aliases go in /etc/bashrc
# --/etc/bashhrc中的功能和別名
#
# This file sets the following features:
# --這個文檔設定下列功能:
#
# o path --路徑
# o prompts --提示符
# o a few environment variables --幾個環境變數
# o colour ls --ls 的顏色
# o less behaviour --設定less的功能
# o keyboard settings --鍵盤設置
#
# Users can override these settings and/or add others in their
# $HOME/.bash_profile
# 用戶可在$HOME/.bash_profile中取消這些設定和(或)增加其他設定
# set a decent path
# 設定可行的路徑
echo $PATH | grep X11R6 > /dev/null
if [ $? = 1 ] ; then # add entries to the path
PATH="$PATH:/usr/X11R6/bin:$HOME/bin:."
fi
# notify the user: login or non-login shell. If login, the prompt is
# coloured in blue; otherwise in magenta. Root@#s prompt is red.
# 通知用戶:登錄(login)或不登錄(non-login)的外圍程序(shell)。
# 如果登錄,則提示符為藍色,否則為紫紅色。Root的提示符為紅色。
USER=`whoami`
if [ $LOGNAME = $USER ] ; then
COLOUR=44
else
COLOUR=45
fi
if [ $USER = @#root@# ] ; then
COLOUR=41
fi
# put a real escape character instead of ^[
# 用真正的換碼字符代替^[
PS1=@#^[[$COLOUR;37;1m$HOSTNAME:^[[37;40;1mw$ @#
PS2="Continue> "
# no core dumps, please
# 請勿轉儲內存信息
ulimit -c 0
# set umask
# 設定umask
if [ `id -gn` = `id -un` -a `id -u` -gt 14 ]; then
umask 002
else
umask 022
fi
# a few variables
# 幾項變數
USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
EDITOR=jed
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
HISTFILESIZE=1000
export PATH PS1 PS2 USER LOGNAME MAIL EDITOR HOSTNAME HISTSIZE HISTFILESIZE
# enable colour ls
# 設定ls的顏色
eval `dircolors /etc/DIR_COLORS -b`
export LS_OPTIONS=@#-F -s -T 0 --color=tty@#
# customize less
# 設定less
LESS=@#-M-Q@#
LESSEDIT="%E ?lt+%lt. %f"
LESSOPEN="| lesspipe.sh %s"
VISUAL=jed
LESSCHARSET=latin1
export LESS LESSEDIT LESSOPEN VISUAL LESSCHARSET
# customise the keyboard
# 設定鍵盤
/sbin/kbdrate -s -r 16 -d 500
for i in /etc/profile.d/*.sh ; do
if [ -x $i ]; then
. $i
fi
done
--------------------------------------------------------------------------------
此處為 /etc/bashrc:
--------------------------------------------------------------------------------
# /etc/bashrc
# System wide functions and aliases
# 整個系統的功能和別名
#
# Environment stuff goes in /etc/profile
# /etc/profile中的環境參數
#
alias which="type -path"
alias d="ls"
alias dir="d"
--------------------------------------------------------------------------------
此處為 .bashrc:
--------------------------------------------------------------------------------
# $HOME/.bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# this is needed to notify the user that they are in non-login shell
# 需要以下設定,以便通知處於不登錄(non-login)外圍程序(shell)中的用戶
COLOUR=45
# put a real escape character instead of ^[
# 用真正的換碼字符代替^[
PS1=@#^[[$COLOUR;37m$USER:^[[37;40mw$ @#
# aliases
# 別名
alias cp=@#cp -i@#
alias l=less
alias lyx=@#lyx -width 900 -height 700@#
alias mv=@#mv -i@#
alias rm=@#rm -i@#
alias x=startx
# A few useful functions
# 幾個有用的功能
inst() # Install a .tar.gz archive in the current directory.
{ gzip -dc $1 | tar xvf - }
cz() # List the contents of a .zip archive.
{ unzip -l $* }
ctgz() # List the contents of a .tar.gz archive.
{
for file in $* ; do
gzip -dc ${file} | tar tf -
done
}
tgz() # Create a .tgz archive a la zip.
{
name=$1 ; tar -cvf $1 ; shift
tar -rf ${name} $*
gzip -S .tgz ${name}
}
--------------------------------------------------------------------------------
此處為.bash_profile:
--------------------------------------------------------------------------------
# $HOME/.bash_profile
# User specific environment and startup programs
# 用戶特定的環境參數和啟動程式
#
# This file contains user-defined settings that override
# those in /etc/profile
# 這個文檔中存有用戶自訂的設置,可取代/etc/profile 中的數值
#
# Get aliases and functions
# 設定別名和功能
#
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# re-get PS1 settings
# 重新設定PS1數值
if [ $USER = @#root@# ] ; then
COLOUR=41
else
COLOUR=44
fi
# put a real escape character instead of ^[
# 用真正的換碼字符代替^[
PS1=@#^[[$COLOUR;37;1m$HOSTNAME:^[[37;40;1mw$ @#
export PS1
--------------------------------------------------------------------------------
此處為 .bash_logout:
--------------------------------------------------------------------------------
# $HOME/.bash_logout
clear
--------------------------------------------------------------------------------
此處為 .inputrc:
--------------------------------------------------------------------------------
# $HOME/.inputrc
# key bindings
# 主要綁定
"e[1~": beginning-of-line
"e[3~": delete-char
"e[4~": end-of-line
# (F1 .. F5) are "e[[A" ... "e[[E"
# (F1 .. F5) 分別為 "e[[A" ... "e[[E"
"e[[A": "info C-m"
set bell-style visible # please don@#t beep
# --喇叭不發聲
set meta-flag On # allow 8-bit input (i.e, aclearcase/" target="_blank" >ccented letters)
# --允許8-位元輸入(例如重音字符)譯注:用于歐洲
# 文字或GB碼及Big5碼)
set convert-meta Off # don@#t strip 8-bit characters
# 不取消8-位元字符
set output-meta On # display 8-bit characters correctly
# 正確顯示8-位元字符
set horizontal-scroll-mode On
set show-all-if-ambiguous On
--------------------------------------------------------------------------------
設定下列參數使 backspace 和 delete 兩鍵在xterm 和其他X11應用中運作正常:
在.xinitrc中添加:
usermodmap=$HOME/.Xmodmap
xmodmap $usermodmap
在.Xmodmap中添加:
keycode 22 = BackSpace
keycode 107 = Delete
以上就設定了主控臺的參數。 要修改xterm,則更改如下:
在.Xdefaults中增添:
xterm*VT100.Translations: #override BackSpace: string(0x7F)
Delete: string(0x1b) string("[3~")
Home: string(0x1b) string("[1~")
End: string(0x1b) string("[4~")
CtrlPrior: string(0x1b) string("[40~")
CtrlNext: string(0x1b) string("[41~")
nxterm*VT100.Translations: #override BackSpace: string(0x7F)
Delete: string(0x1b) string("[3~")
Home: string(0x1b) string("[1~")
End: string(0x1b) string("[4~")
CtrlPrior: string(0x1b) string("[40~")
CtrlNext: string(0x1b) string("[41~")
在bash(1) 和 readline(3) 的man說明中有更多這方面的資料。
不要以為這些設定在每種應用中都可正常運作。例如,在xterm中運行joe,有些鍵位就不起作用;運行rxvt也有相同的問題。有人說,這是termcap的問題。