Shell特性

命令 含义
> 重定向输出
>> 追加到文件
< 重定向输入
<< "Here"文档 (重定向输入)
| 管道输出
& 在后台运行进程
; 同一行的分隔符
* 文件名统配符(多个字符)
? 文件名统配符(单个字符)
[ ] 匹配任何包含的字符
( ) 在子shell运行
` ` 代替包含命令的输出
" " 部分引用(允许变量和命令表达式)Partial quote (allows variable and command expansion)
' ' 全引用 (没有扩展)Full quote (no expansion)
\ 引用跟随字符Quote following character
$var 对变量取值
$$ 进程号
$0 命令名
$n 第n个参数 (n从0到9)
$* 所有参数作为一个词
# 注释的开始
bg 后台执行
break 从循环语句跳出
cd 更改目录
continue 继续程序循环
echo 显示输出
eval 评估参数(读取变量用于组合新命令)
exec 执行一个新的shell
fg 前台执行
jobs 现实活动作业
kill 中止运行的作业
newgrp 更换到一个新组
shift Shift positional parameters
stop 挂起一个后台作业
suspend 挂起一个前台作业
time 对命令计时
umask 设置或列出文件权限
unset 擦除变量或者函数定义
wait 等待一个后台程序完成

 » 相关连接:
捕捉信号 变量进阶 shift内建命令 使用select内建命令来制作菜单
I/0 重定向和循环 read取得用户输入 echo命令使用的转义序列 shell实现Unix进程间信息交换的几
sed与unix命令等价代码鉴赏 关于>&2、2>&1等重定向的详 Shell环境和变量生存期 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 里面工作,但是反之不然。

表 A.2. 不同shell的特性

sh bash ksh csh Meaning/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 $home Home目录

~ ~ ~ Home目录符号

~+, ~-, dirs ~+, ~- =-, =N 访问目录栈
var=value VAR=value var=value set var=value 变量赋值
export var export VAR=value export var=val setenv var val 设置环境变量

${nnnn} ${nn}
More than 9 arguments can be referenced
"$@" "$@" "$@"
All arguments as separate words
$# $# $# $#argv Number of arguments
$? $? $? $status Exit status of the most recently executed command
$! $! $!
PID of most recently backgrounded process
$- $- $-
Current options
. file source file or . file . file source file Read commands in file

alias x='y' alias x=y alias x y Name x stands for command y
case case case switch or case Choose alternatives
done done done end End a loop statement
esac esac esac endsw End case or switch
exit n exit n exit n exit (expr) Exit with a status
for/do for/do for/do foreach Loop through variables

set -f, set -o nullglob|dotglob|nocaseglob|noglob
noglob Ignore substitution characters for filename generation
hash hash alias -t hashstat Display hashed commands (tracked aliases)
hash cmds hash cmds alias -t cmds rehash Remember command locations
hash -r hash -r
unhash Forget command locations

history history history List previous commands

ArrowUp+Enter or !! r !! Redo previous command

!str r str !str Redo 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
fi fi fi endif End if statement
ulimit ulimit ulimit limit Set resource limits
pwd pwd pwd dirs 打印工作目录
read read read $< Read from terminal
trap 2 trap 2 trap 2 onintr 忽略中断

unalias unalias unalias 去除别名
until until until
开始 until 循环
while/do while/do while/do while 开始 while 循环

 » 相关连接:
捕捉信号 变量进阶 shift内建命令 使用select内建命令来制作菜单
I/0 重定向和循环 read取得用户输入 echo命令使用的转义序列 shell实现Unix进程间信息交换的几
sed与unix命令等价代码鉴赏 关于>&2、2>&1等重定向的详 Shell环境和变量生存期 SHELL正则表达式语法
 » 本栏目最新帖:

Powered by PHPWind v6.0 Code © 2003-08