ShellStepbyStep (3) -- Stdin & if

Source: Internet
Author: User

ShellStepbyStep (3) -- Stdin & if

4. Input and Output

#! /bin/bash# Read users input and then get his nameread -p "Please input your first name: " firstNameread -p "Please input your last name: " lastNameecho -e "Your full name is:   $firstName  $lastName"

Read usage:

Read [-ers] [-a array] [-d separator] [-I buffer text] [-n read characters] [-N read characters] [-p prompt] [-t timeout] [-u file descriptor] [name...]

5. Conditional Discriminant

-E whether-nt (newer than) file1 is newer than file2-ot (older than) Whether file1 is earlier than file2-ne indicates not equal to-eq, such: if ["$ a"-eq "$ B"]-ne is not equal to, for example, if ["$ a"-ne "$ B"]-gt is greater than, for example: if ["$ a"-gt "$ B"]-ge is greater than or equal to, for example, if ["$ a"-ge "$ B"]-lt is less than, for example: if ["$ a"-lt "$ B"]-le is less than or equal to, for example: if ["$ a"-le "$ B"] <less than (double parentheses are required), such as: ("$ a" <"$ B ")) <= less than or equal to (double parentheses required), such as: ("$ a" <= "$ B")> greater than (double parentheses required ), for example: ("$ a"> "$ B")> = equal to or greater than (double parentheses are required), for example: ("$ a"> = "$ B ")) -z (zero) is zero?
[-A FILE] true if the FILE exists. [-B FILE] If the FILE exists and is a special block FILE, it is true. [-C FILE] If the FILE exists and is a special word FILE, it is true. [-D FILE] If the FILE exists and is a directory, it is true. [-E FILE] If the FILE exists, it is true. [-F FILE] If the FILE exists and is a normal FILE, it is true. [-G FILE] If the FILE exists and the SGID has been set, it is true. [-H FILE] If the FILE exists and is a symbolic connection, it is true. [-K FILE] true if the FILE exists and the stick bits have been set. [-P FILE] If the FILE exists and is a name pipe (F If O), it is true. [-R FILE] true if the FILE exists and is readable. [-S FILE] If the FILE exists and the size is not 0, it is true. [-T FD] It is true if the file descriptor FD is opened and points to a terminal. [-U FILE] If the FILE exists and SUID (set user ID) is set, it is true. [-W FILE] true if the FILE exists and is writable. [-X FILE] true if the FILE exists and is executable. [-O file] true if the FILE exists and belongs to a valid user ID. [-G file] true if the FILE exists and belongs to a valid user group. [-L file] If the FILE exists and is a symbolic connection, it is true. [-N file] If FILE exists and has been mod, it is true if ied since it was last read. [-S file] If the FILE exists and is a socket, it is true. [FILE1-nt FILE2] If FILE1 has been changed more recently than FILE2, or if FILE1 exists and FILE2 does not is true. [FILE1-ot FILE2] True if FILE1 is older than FILE2, or if FILE2 exists and FILE1 does not exist. [FILE1-ef FILE2] True if FILE1 and FILE2 point to the same device and node number. [-O OPTIONNAME] true if the shell option "OPTIONNAME" is enabled. [-Z STRING] "STRING" is true if its length is zero. If the length of [-n STRING] or [STRING] "STRING" is non-zero, it is true. [STRING1 = STRING2] If the two strings are the same. "=" May be used instead of "=" for strict POSIX compliance is true. [STRING1! = STRING2] true if the strings are not equal. [STRING1 <STRING2] True if "STRING1" sorts before "STRING2" lexicographically in the current locale. [STRING1> STRING2] True if "STRING1" sorts after "STRING2" lexicographically in the current locale. [ARG1 OP ARG2] "OP" is one of-eq,-ne,-lt,-le,-gt or-ge. these arithmetic binary operators return true if "ARG1" is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to "ARG2 ", respectively. "ARG1" and "ARG2" are integers.

e.g:

if [ "$UID" -ne "$ROOT_UID" ] then ……

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.