Shell judgment and Comparison

Source: Internet
Author: User

Shell judge and compare 1 shell $!, $ ?, $, $ @ $ N $1 the first parameter, $2 the second... $ # The number of command-line parameters. $0 The name of current program. $? Last command or function's return value. $ The program's PID. $! Last program's PID. $ @ Save all the parameters. almost any shell book will talk about them, from which you can get their detail usages. 2 Linux SHELL if command parameter description-B returns true if file exists and is a block file-c returns true if file exists and is a character file-d returns true if pathname exists and is a directory returns true-e when the file or directory specified by pathname exists, returns true-f when the file exists and is a regular file, returns true-g when the file or directory specified by pathname exists and if the SGID bit is set, return true-h. If the file exists and is a symbolic link file, return true, this option is invalid in some old systems.-k. When the file or directory specified by pathname exists and the "Sticky" bit is set, the system returns true-p. When the file exists and is a command Pipeline Returns true-r. When a file or directory specified by pathname exists and is readable, returns true-s. When the file size is greater than 0, returns true-u. When the file or directory specified by pathname if the SUID bit exists and is set, true is returned. If the file or directory specified by pathname exists and is executable, true is returned. A directory must be executable for its content access. -O returns true if a file or directory specified by pathname exists and the user specified by the valid user ID of the current process is owned by it. Compare characters in UNIX Shell:-eq equals-ne is not equal to-gt is greater than-lt is less than-le is less than or equal to-ge is greater than or equal to-z empty string = two characters are equal! = Two character unequal-n non-empty string Summary: The comparison operator-e filename if filename exists, it is true [-e/var/log/syslog]-d filename if filename is a directory, it is true [-d/tmp/mydir]-f filename. If filename is a regular document, it is true [-f/usr/bin/grep]-L filename. If filename is a symbolic link, true [-L/usr/bin/grep]-r filename if filename is readable, true [-r/var/log/syslog]-w filename if filename is writable, true [-w/var/mytmp.txt]-x filename if filename is executable, true [-L/usr/bin/grep] filename 1-nt filename2 if filename1 is newer than filename2, then true [/tmp/install/etc/services-nt/etc/services] filename1-ot filename2 if filename1 is older than filename2, it is a true [/boot/bzImage-ot arch/i386/boot/bzImage] string comparison operator (please note the use of quotation marks, this is a good way to prevent space from disturbing the code) -z string if the string length is zero, it is true [-z "$ myvar"]-n string if the string length is not zero, true [-n "$ myvar"] string1 = string2 if string1 and string2 are the same, true ["$ myvar" = "one two three"] string1! = String2 if string1 is different from string2, it is true ["$ myvar "! = "One two three"] arithmetic comparison operator num1-eq num2 equals [3-eq $ mynum] num1-ne num2 not equal to [3-ne $ mynum] num1-lt num2 less than [3-lt $ mynum] num1-le num2 less than or equal to [3-le $ mynum] num1-gt num2 greater than [3-gt $ mynum] num1-ge num2 greater than or equal to [3-ge $ mynum]

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.