Basic shell command parameters

Source: Internet
Author: User
Shell command basic parameters in shell programming use the if statement to determine the parameter & amp; ndash; b. If the file exists and is a block file, true is returned.-c. If the file exists and is a character file, true is returned.-d. If the pathname exists and is a directory, true-e is returned as path. .. shell command basic parameter shell programming using the if statement to determine the parameter-B when the file exists and is a block file returns true-c when the file exists and is a character file returns true- d. when the pathname exists and is a directory, true-e is returned. when the file or directory specified by pathname exists, true-f is returned. when the file exists and is a regular file, true-g is returned. if the file or directory specified by pathname exists and the SGID bit is set, the returned result is true-h. If the file exists and is a symbolic link file, the returned result is 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 ------------------------------------------------------------------------- for more details: operator description example file 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 file, it is true [-f/usr/bin/grep]-L filename. if filename is a symbolic link, it is true [-L/usr/bin/grep]-r filename. if filename is readable, it is true [-r/var/log/syslog]-w filename if f Ilename can be written, it is true [-w/var/mytmp.txt]-x filename if filename can be executed, true: [-L/usr/bin/grep] filename1-nt filename2. if filename1 is newer than filename2, if [/tmp/install/etc/services-nt/etc/services] filename1-ot filename2 is earlier 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, it is true. [-N $ myvar] string1 = string2 if string1 is the same as string2, it is 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 to [3-eq $ mynum] num1-ne num2 not equal to [3-ne $ mynum] num1-lt num2 less than [3 -lt $ mynum] num1-le num2 is less than or equal to [3-le $ mynum] num1-gt num2 is greater than [3-gt $ mynum] num1-ge num2 is greater than or equal to [3 -ge $ mynum] $ # Number of location parameters. $ * Content of all location parameters. $? Status returned after the command is executed. $ Process ID of the current process. $! The last process number that runs in the background. $0 indicates the name of the currently executed process. Where, $? Used to check whether the previous command is correctly executed. (In Linux, if the exit status of a command is 0, the command is correctly executed. if the value is not 0, an error occurs .)
 
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.