`
sjk2013
  • 浏览: 2191609 次
文章分类
社区版块
存档分类
最新评论

条件测试

 
阅读更多

-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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics