Shell Step by Step (3)--stdin & IF

Source: Internet
Author: User
Tags locale sorts stdin

4. Input and output

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

Read usage:

read[-ers][-a 数组][-d 分隔符][-i 缓冲区文字]      [-n 读取字符数][-N 读取字符数][-p 提示符]      [-t 超时][-u 文件描述符][名称 ...]

5. Conditional discriminant Formula

- eIs there a-nt (newer than) file1 is better than file2 new-ot (older than) file1 than file2 old-neIndicates not equal to-eqEquals, as:if["$a" -eq "$b"]-neNot equal to, as:if["$a" -ne "$b"]-GTGreater than, as:if["$a" -GT "$b"]-ge is greater than or equal to, such as:if["$a"-ge"$b"]-ltLess than, such as:if["$a" -lt "$b"]-le less than equals, such as:if["$a"-le"$b"]< is less than (requires double brackets), such as: (("$a"<"$b") <= is less than or equal (requires double brackets), such as: (("$a"<="$b") > Greater than (requires double brackets), such as: (("$a">"$b") >= is greater than or equal to (requires double brackets), such as: (("$a">="$b")-Z (zero)
[-AFILE] IfFILEThe existence is true. [-BFILE] IfFILEExists and is a block special file is true. [-CFILE] IfFILEexists and is a word special file is true. [-DFILE] IfFILEexists and is a directory is true. [-EFILE] IfFILEThe existence is true. [-FFILE] IfFILEexists and is an ordinary file is true. [-GFILE] IfFILEexists and the Sgid is set to true. [-HFILE] IfFILEIs true if it exists and is a symbolic connection. [-KFILE] IfFILEexists and the sticky bit has been set is true. [-PFILE] IfFILEexists and is a name pipe (f if O) is true. [-RFILE] IfFILEIs true if it exists and is readable. [-SFILE] IfFILEexists and is not of the size0Is true.  [-T FD] true if the file descriptor FD is open and points to a terminal. [-UFILE] IfFILESuid is present and set (SetUser ID) is true. [-WFILE] IfFILEIfFILEIs true if it exists and is writable. [-XFILE] IfFILEIs true if it exists and is executable. [-OFILE] IfFILEexists and is valid user ID is true. [-GFILE] IfFILEexists and is valid user group is true. [-LFILE] IfFILEIs true if it exists and is a symbolic connection. [-NFILE] IfFILEExist andhas beenMoDIf the IED since it is lastReadIs true. [-SFILE] IfFILEexists and is a socket is true.
[File1-nt FILE2] If FILE1 have been changed more recently than FILE2,orIf FILE1 exists andFILE2does  notIs true.  [File1-ot FILE2] If FILE1 is older than FILE2, or FILE2 exists and FILE1 does not exist, it is true.  [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 turned on.       [-Z STRING]  "STRING" is true if the length is zero. [-N STRING]or[STRING]  The length of "STRING" is not 0 Non-zero is true. [STRING1 = = STRING2] If2The same string. "=" may be usedinstead of"= =" forStrict POSIX compliance is true. [STRING1! = STRING2] True if the strings are not equal. [STRING1 < STRING2] if "STRING1" sortsbefore"STRING2" lexicographicallyinch  theThe current locale is true. [STRING1 > STRING2] If "STRING1" sorts After"STRING2" lexicographicallyinch  theThe current locale is true.    [ARG1 OP ARG2] "OP" isOne of-eq,-ne,-lt,-le,-GTor-ge. These arithmetic binary operatorsreturn true if"ARG1" is                     Equal  to, not Equal  to,Less than, less thanor Equal  to,Greater than,or                     Greater than or Equal  to"ARG2", respectively. "ARG1" and"ARG2" is integers.

e.g:

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

Top Picks

  • LNMP Environment Construction--nginx Chapter

  • Configuring the local Yum source in RHEL6.5

  • Installation and use of Zabbix under Ubuntu

  • MySQL Dual master hot standby problem processing

Shell Step by Step (3)--stdin & if

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.