Linux Shell Common syntax

Source: Internet
Author: User

Conditions

= equals applies To: integer or string comparison if in [], only the string
! = is not equal to: integer or string comparison if in [], only the string

-eq equals applies To: integer comparison

-ne not equal to: integer comparison
-lt less than applied to: integer comparison
-GT greater than applied: integer comparison
-le less than or equal to: integer comparison
-ge greater than or equal to: integer comparison
-A both are established (and) logical Expressions –a logical expressions
-O unilateral formation (or) logical expression –o logical expression
-Z Empty string
-N Non-empty string

-F Common! Detect if "Archive" exists eg:if [-f filename]
-D Common! Detects if the directory exists
-B Detection is a "block file"
-C detection is a "character file"
-S detection is a "socket tag file"
-L detection is a "symbolic Link's profile"
-E detects if "something" exists!
2. About the program's Logical volume label!
-g detection is owned by the program performed by the GID
-O detection is owned by the program executed by the UID
-P detects if a name pipe or FIFO is being transmitted between programs (to be honest, this is not a good idea!) )
3. About the property of the file detection!
-R to detect if a property is readable
-W detection is a property that can be written
-X detect whether the property is executable
-S detection is a "non-blank file"
-U detect if a property with "SUID"
-G detection for properties with "SGID"
-K Detect if there is a property of "sticky bit"
4. Judgment and comparison between two files; for example [Test file1-nt file2]
-nt the first file is newer than the second one.
-ot The first file is older than the second one.
-ef The first file is the same file as the second file (link and other files)
5. Logical "and" "or (OR)"
The meaning of && logic
|| The meaning of a logical OR

For i in ' seq 5 6 '
Do
echo "for" $i
Done

Count=0
Until [$count-GT 1]
Do
Count= ' expr $count + 1 '
echo "Until" $count
Done
While [$count-GT 1]
Do
count= ' Expr $count-1 '
echo "while" $count
Done

if [1 = 1] && [2-eq 2]; Then
echo "If"
elif [1 = 1]; Then
echo "Elif"
Else
echo "Else"
Fi


echo "AAA123BBB" | Awk-f[0-9] ' {print $ ': ' $ '-' $4;} '

Linux Shell Common syntax

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.