Shell Test []

Source: Internet
Author: User

Http://man.linuxde.net/test
Http://blog.chinaunix.net/uid-24780853-id-2578709.html

[email protected] ~]# man testtest (1) User Commands Test (1) NAME test - Check file types and compare Valuessynopsis Test EXPRESSION t EST [EXPRESSION] [] [Optiondescription Exit with the status determined by EXPRESSION. --help Display this help and exit --version output version information and E XIT an omitted EXPRESSION defaults to false.
Otherwise, EXPRESSION is true or false and sets exit status. It 's one of : (expression) EXPRESSION is true ! expression Expression is false

If the choice is executed with $? return value About
Test = = []
------------------------------------------------------------------

[Email protected] ~]# test
[[email protected] ~]# echo $?
1

[[Email protected] ~]# []
[[email protected] ~]# echo $?
1

--------------------------------------------------------------------------

(LS) differs from $ (LS):

(LS) executes the LS command in the child shell, and the screen displays the result

a=$ (LS): The LS executes the command result, that is, the output value is placed in the variable A, redirected output to a (excluding error output)

[[Email protected] kk]# (LS)
Mm
[[email protected] kk]# echo $?
0

[[Email protected] kk]# (LS TT)
LS: Unable to access TT: No file or directory
[[email protected] kk]# echo $?
2

[[email protected] kk]#! Ls
Mm
[[email protected] kk]# echo $?
1

Description "!": Action is $? Take counter

--------------------------------------------------------------------------------------------------------------- --------------

echo $ ((2>1))

1

echo $ ((2==1))

0

echo $ ((2<1))

0

a=$ ((2+1))
b=$ ((2-1))
c=$ ((2*1))
d=$ ((2/1))

-------------------------------------------------------------------------------------

[[email protected] kk]# true
[[email protected] kk]# echo $?
0
[[email protected] kk]# false
[[email protected] kk]# echo $?
1

--------------------------------------------------------------------------

-A :
-o:expression1-a EXPRESSION2 both EXPRESSION1 and EXPRESSION2 aretrueEXPRESSION1-o EXPRESSION2 either EXPRESSION1 or EXPRESSION2 is true
---------------------------------------------------------------------------------------string:
-n String the length of string isnonzero STRING equivalent to-N STRING-Z String The length of string isZero STRING1=STRING2 the strings is equal STRING1!=STRING2 the strings is not equal
------------------------------------------------------------------------------------------------------------Integral type: INTEGER1-eq INTEGER2 INTEGER1 isequal to INTEGER2 INTEGER1-GE INTEGER2 INTEGER1 isgreater than or equal to INTEGER2 INTEGER1-GT INTEGER2 INTEGER1 isgreater than INTEGER2 INTEGER1-le INTEGER2 INTEGER1 isLess than or equal to INTEGER2 INTEGER1-LT INTEGER2 INTEGER1 isLess than INTEGER2 INTEGER1-NE INTEGER2 INTEGER1 isNot equal to INTEGER2
--------------------------------------------------------------------------------------------------------------- ------------------Files: FILE1-EF FILE2 FILE1 and FILE2 have the same device and inode numbers FILE1-NT FILE2 FILE1 isNewer (modification date) than FILE2 FILE1-ot FILE2 FILE1 isolder than FILE2-b file File exists and isBlock Special-c file File exists and isCharacter Special-d file file exists and isa directory-e file file exists-f file File exists and isa regular file-g file file exists and is Set-group-ID-G file file exists and isowned by the effective group ID-h file file exists and isA symbolic link (same as-L)-k file file exists and have its sticky bitSet-L file file exists and isA symbolic link (same as-h)-O file file exists and isowned by the effective user ID-p file File exists and isa named pipe-r file file exists and Read permission isgranted-s file file exists and has a size greater than zero-S file file exists and isa socket-T FD file descriptor FD isopened on a terminal-u file file exists and itsSet-user-id bit is Set-w file file exists and write permission isgranted-x file file exists and execute (or search) permission isgranted
--------------------------------------------------------------------------------------------------------------- ----------------Except for-H and-l, all file-related tests dereference symbolic links. Beware that parentheses need to being escaped (e.g., by backslashes) forShells. INTEGER may also is-l string, which evaluates to the length of string. Note: [Honors the--help and--version options, but test does not. Test treats each of the those asit treats any other nonempty STRING. Note:your Shell May has its own version of Test and/or [, which usually supersedes the version described here. Refer to your shell ' s documentation forDetails about the options it supports.




Shell Test []

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.