Shell 是介于操作系统和用户之间的界面,它能解释用户发出的命令,启动应用程序,并利用系统功能管理用户数据。Shell 可以在用户的交互式控制下在前台或后台同时运行多个进程,Shell 同时也是一种有效的编程语言。


1、通配符

(1)*:多个任意字符

$ ls

info newdir test.file testfile

mbox newtest.file test1.file wangyi

$ ls *.*

newtest.file test.file test1.file


(2)?:单个任意字符

$ ls ????.*

test.file


(3) [ ]:在[ ]之间的单个字符

$ ls [mt]*

mbox test.file test1.file


(4)[ - ]:在[ - ]范围内的单个字符

$ ls [m-w]*

mbox newtest.file test.file test1.file testfile

newdir:

wangyi:


(5)!:非某个或某些字符

$ ls [!t]*

mbox newtest.file

info:

notes tmp

newdir:

wangyi:

test.file


2、标准输入输出

在 AIX 标准状态下,输入来自键盘,输出是到屏幕,出错信息也是显示在屏幕上。

重定向符号 系统变量名

标准输入 < (<<) 0

标准输出 > (>>) 1

标准错误输出 2> (2>>) 2


3/重定向

在 AIX 的环境中标准的输入、输出和错误信息均可以重新定向,使用户可以从键盘以外的其他地方(如文件,串口等)获取输入信息,并把输入的内容和出错的信息送到屏幕之外的其他地方(如文件等)。

●输入重定向

$ command < filename

$ mail xumin < test.file

● 输出重定向

$ command > filename

$ ls > out.file

$ cat out.file

28

info

mbox

newdir

newtest.file

out.file

test.file

test1.file

testfile

wangyi

● 错误信息重定向

$ command 2> filename

$ ls test2.file 2> error.out

$ cat error.out

ls: 0653-341 The file test2.file does not exist.

● 组合重定向

$ command < infile > outfile 2> errfile

$ command > outfile 2> errfile < infile

$ ls test1.file test2.file > out.file 2> error.file

$ cat out.file

test1.file

$ cat error.file

ls: 0653-341 The file test2.file does not exist.

●关联组合重定向

$ command > outfile 2> &1

这里的&1 指向 out.file,因为此时原来系统的标准输出已被重定向为 out.file。

$ command 2> &1 > outfile

这里的&1 指向标准输出,此时原来系统的标准输出尚未改变。


4、管道

管道的作用是把前一个命令的输出作为后一个命令的输入。

管道的用法:

$ command1 | command2

$ ls | wc -w


5、分割输出

tee 这个命令可以读取标准输入,并把数据同时送到标准的输出和指定的文件中

tee 的用法:

$ command1 | tee filename | command2

$ ls | tee out.file | wc

11 11 97

$ cat out.file

error.file

error.out

info

mbox

newdir

newtest.file

out.file

test.file

test1.file

testfile


6、多个命令

在 AIX 中 shell 允许在同一行中写多个命令,只需要在命令之间加上“;”作为分隔符

用法:

$ command1 ; command2 ; command3

$ pwd;cd /;ls

/home/xumin

Slider.class dead.letterlost+found smit.script usr

TT_DB dev lpp testnfs var

aaaa etc mnt testxmg websm.log

adsmtest home opt testxmg2 xumin

bin info sbin tftpboot xumin_disk1

cdrom info.www share tmp

cds.types informix showcase u

core lib smit.log unix


7、长命令

在 AIX 的 shell 中写较长的命令时,可以使用“\”作为换行的标记,这时 shell 会用一个“>”作为提示符。


8、Shell 环境中的变量

在 shell 环境下面可以定义变量,供系统、用户,shell 程序和各种应用使用。变量可以由系统定义,也可以由用户自己定义。系统已经定义的变量用户也可以修改或删除。

例如: HOME -- 用户的 home 目录

TERM -- 终端类型

PATH -- 命令搜索路径


9、变量的查看和定义

(1)查看已定义过的变量

$ set

~~~

~~~

HOME=/home/xumin

LANG=En_US

LOCPATH=/usr/lib/nls/loc

LOGIN=xumin

LOGNAME=xumin

MAIL=/usr/spool/mail/xumin

MAILCHECK=600

MAILMSG='[YOU HAVE NEW MAIL]'

~~~

~~~

PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/xumin/bin:/usr/bin/X11:/sbin:.

PPID=69504nput

PS1='$ '

PS2='> '

PS3='# '

PS4='+ '

PWD=/

RANDOM=31884

32

SECONDS=2774

SHELL=/usr/bin/ksh

TERM=ANSI

TERM_DEFAULT=lft

TMOUT=0

TZ=CST6CDT

USER=xumin


(2)显示变量值

$ echo $name

$ echo $HOME

/home/xumin


(3)定义变量

$ name=value

$ echo $xxx

$ xxx=hello!

$ echo $xxx

hello!


(4)删除变量

$ unset

$ unset xxx

$ echo $xxx


(5)变量的运用

' ':把' '之间的内容作为一个命令,返回命令的结果

$ now=`date`

$ echo $now

Wed Aug 12 15:23:19 CDT 1998

' ' :不解释 ' ' 之间的任何内容

$ echo '$HOME'

$HOME

“”:会解释“”之间的 $、` `、\等字符的特殊含义

$ echo “now is `date`”

now is Wed Aug 12 15:32:41 CDT 1998

\ :忽略\之后的特殊字符的特殊含义

$ echo \$HOME

$HOME


oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html