不同Shell的特性

下表列出了标准shell(sh), Bourne Again SHell (bash), Korn shell (ksh) 和 C shell (csh)之间的主要区别.

 Shell兼容性

既然Bash是 sh 的超集,那么所有的 sh 命令将仍然能在bash里面工作,但是反之则不然。 bash 有很多自己的特性,而且,就像下表证明的,很多特性混合自其他shell。

既然Turbo C shell是 csh 的超集,那么所有的 csh 命令也能在 tcsh 里面工作,但是反之不然。

表  不同shell的特性

shbashkshcshMeaning/Action
$$$%默认用户提示
 >|>|>!强制重定向
> file 2>&1&> file 或者 > file 2>&1> file 2>&1>& file重定向标准输出和标准错误到 文件
 { } { }扩展列表中的元素
`command``command` or $(command)$(command)`command`Substitute output of enclosed command
$HOME$HOME$HOME$homeHome目录
 ~~~Home目录符号
 ~+, ~-, dirs~+, ~-=-, =N访问目录栈
var=valueVAR=valuevar=valueset var=value变量赋值
export varexport VAR=valueexport var=valsetenv var val设置环境变量
 ${nnnn}${nn} More than 9 arguments can be referenced
"$@" "$@" "$@"  All arguments as separate words
$#$#$#$#argvNumber of arguments
$?$?$?$statusExit status of the most recently executed command
$!$!$! PID of most recently backgrounded process
$-$-$- Current options
. filesource file or . file. filesource fileRead commands in file
 alias x='y'alias x=yalias x yName x stands for command y
casecasecaseswitch or caseChoose alternatives
donedonedoneendEnd a loop statement
esacesacesacendswEnd case or switch
exit nexit nexit nexit (expr)Exit with a status
for/dofor/dofor/doforeachLoop through variables
 set -f, set -o nullglob|dotglob|nocaseglob|noglob noglobIgnore substitution characters for filename generation
hashhashalias -thashstatDisplay hashed commands (tracked aliases)
hash cmdshash cmdsalias -t cmdsrehashRemember command locations
hash -rhash -r unhashForget command locations
 historyhistoryhistoryList previous commands
 ArrowUp+Enter or !!r!!Redo previous command
 !strr str!strRedo last command that starts with “str
 !cmd:s/x/y/r x=y cmd!cmd:s/x/y/Replace “x” with “y” in most recent command starting with “cmd”, then execute.
if [ $i -eq 5 ]if [ $i -eq 5 ]if ((i==5))if ($i==5)Sample condition test
fififiendifEnd if statement
ulimitulimitulimitlimitSet resource limits
pwdpwdpwddirs打印工作目录
readreadread$<Read from terminal
trap 2trap 2trap 2onintr忽略中断
 unaliasunaliasunalias去除别名
untiluntiluntil 开始 until 循环
while/dowhile/dowhile/dowhile开始 while 循环

Bash还有很多这里没有列出的特性。这个表 Bourne Again SHell has many more features not listed here. This table is just to give you an idea of how this shell incorporates all useful ideas from other shells: there are no blanks in the column for bash. More information on features found only in Bash can be retrieved from the Bash info pages, in the “Bash Features” section.

更多信息:

You should at least read one manual, being the manual of your shell. The preferred choice would be info bash, bash being the GNU shell and easiest for beginners. Print it out and take it home, study it whenever you have 5 minutes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值