条件测试

-rw-r--r-- 1 oracle oinstall  2653 Feb 23 21:30 awk.out

-rwxr--r-- 1 oracle oinstall  2250 Feb 23 21:20 awk.sh

-rw-r--r-- 1 oracle oinstall   216 Feb 23 11:53 blank_file

-rwxr--r-- 1 oracle oinstall   642 Feb 15 18:43 find.sh

drwxr-xr-x 2 oracle oinstall  4096 Feb 15 17:56 folder

-rw-r--r-- 1 oracle oinstall   620 Feb 24 14:21 ls.out

-rw-r--r-- 1 oracle oinstall   620 Mar  2 14:00 ls.out2

-rwxr-xr-x 1 oracle oinstall    26 Nov 10 22:30 main.sh

-rw-r--r-- 1 oracle oinstall 13956 Mar  6 21:49 orclsid_ora_31518_lubinsu.out

-rw-r--r-- 1 oracle oinstall   608 Mar  3 14:48 result.out

drwxr-xr-x 2 oracle oinstall  4096 Feb 25 22:10 sed.folder

-rwxrwxrwx 1 oracle oinstall    44 Jan  7 22:39 shelltest.sh

drwxr-xr-x 2 oracle oinstall  4096 Mar  3 12:14 sort.folder

-rwxr-xr-x 1 oracle oinstall    99 Feb 23 11:51 test1.sh

-rwxr-xr-x 1 oracle oinstall    99 Feb 23 11:52 test2.sh

drwxr-xr-x 2 oracle oinstall  4096 Mar  3 15:07 tr.folder

[oracle@localhost testDir]$ ll awk

ls: awk: No such file or directory

[oracle@localhost testDir]$ ls -l awk.out

-rw-r--r-- 1 oracle oinstall 2653 Feb 23 21:30 awk.out

[oracle@localhost testDir]$ [ -w awk.out ]

[oracle@localhost testDir]$ echo $?

0

[oracle@localhost testDir]$ [ -x awk.out ]

[oracle@localhost testDir]$ echo $?       

1

[oracle@localhost testDir]$ test -x awk.out

[oracle@localhost testDir]$ echo $?

1

[oracle@localhost testDir]$ test -d folder

[oracle@localhost testDir]$ echo $?

0

[oracle@localhost testDir]$

[oracle@localhost testDir]$ test -u test1.sh

[oracle@localhost testDir]$ echo $?

1

[oracle@localhost testDir]$ [ -x test1.sh -a -w test2.sh ]

[oracle@localhost testDir]$ echo $?

0

[oracle@localhost testDir]$ [ -w result.out -a -x result.out ]

[oracle@localhost testDir]$ echo $?

1

[oracle@localhost testDir]$ [ -w result.out -o -x result.out ]

[oracle@localhost testDir]$ echo $?

0

[oracle@localhost testDir]$ [ -z $EDITOR ]

[oracle@localhost testDir]$ echo $?

0

[oracle@localhost testDir]$ [ $EDITOR = "vi" ]

-bash: [: =: unary operator expected

[oracle@localhost testDir]$ [ $EDITOR = "vi" ]

-bash: [: =: unary operator expected

[oracle@localhost testDir]$ [ $EDITOR = "vi" ]

-bash: [: =: unary operator expected

[oracle@localhost testDir]$ echo $EDITOR

[oracle@localhost testDir]$ testStr=vi

[oracle@localhost testDir]$ echo $testStr

vi

[oracle@localhost testDir]$ [ $testStr = "vi" ]

[oracle@localhost testDir]$ echo $?

0

[oracle@localhost testDir]$ [ $testStr = "v" ]

[oracle@localhost testDir]$ echo $?           

1

[oracle@localhost testDir]$ expr 10 + 10

20

[oracle@localhost testDir]$ expr 10 + 100

110

 

 

130310

[oracle@localhost testDir]$ var1=`date +%Y%m%d`

[oracle@localhost testDir]$ echo ${var1}       

20130310

[oracle@localhost testDir]$ expr ${var1}+1

20130310+1

[oracle@localhost testDir]$ expr ${var1} + 1

20130311

 

 

[oracle@localhost testDir]$ loop=1

[oracle@localhost testDir]$ loop=`expr ${loop} + 1`

[oracle@localhost testDir]$ echo ${loop}

2

 

--模式匹配功能

 

[oracle@localhost testDir]$ var2=word.doc              

[oracle@localhost testDir]$ expr $var2 : '\(.*\).doc'

word

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值