In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the syntax of script sentences commonly used in linux shell. In daily operation, I believe that many people have doubts about the syntax of script sentences commonly used in linux shell. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of script sentence syntax commonly used in linux shell. Next, please follow the editor to study!
If statement syntax in 1shell
I find that sometimes it is equivalent to using eq, sometimes it is expressed as = standard, I don't understand.
=
Eq value
= string!
=
You can take a look at man test
=
Process control
The if expression executes the following part of the then if the condition is true:
If....
Then
....
Elif....
Then
....
Else
....
Fi
In most cases, you can use test commands to test conditions. For example, you can compare strings, determine whether the file exists and whether it is readable and so on.
Conditional tests are usually represented by []. Notice that the spaces here are very important. Make sure the square brackets are blank.
[- f somefile]: determine whether it is a file or not
[- x / bin/ls]: determine whether / bin/ls exists and has executable permission
[- n $var]: determine whether the $var variable has a value
[$a = $b]: judge whether $an and $b are equal
=
I saw a book today, which says that if you use the =, etc. Comparison symbol in the if sentence, it should be written in parentheses, and if you use-eq,-lt, it should be written in [], right?
=
This should be aimed at ksh/bash, because they all extend the original sh and can be used directly
< >= to make a numerical judgment, but as you mentioned, write it in ().
=
The judgment after if is test syntax, while
If [expression] and
If test expression
Is equivalent.
+ +
Test command usage:
1) judgment expression
If test (expression is true)
If test! The expression is false
Test expression 1-an expression 2 both expressions are true
Test expression 1-o expression 2 one of the two expressions is true
2) judge string
The length of test-n string string is non-zero
The length of the test-z string string is zero
Test string 1 = string 2 string equal
Test string 1! = string 2 string is not equal
3) judge integers
Test integers 1-eq integers 2 integers equal
Test Integer 1-ge Integer 2 Integer 1 greater than or equal to Integer 2
Test Integer 1-gt Integer 2 Integer 1 is greater than Integer 2
Test Integer 1-le Integer 2 Integer 1 less than or equal to Integer 2
Test Integer 1-lt Integer 2 Integer 1 is less than Integer 2
Test Integer 1-ne Integer 2 Integer 1 is not equal to Integer 2
4) judgment document
Both test File1-ef File2 files have the same device number and I node number
Test File1-nt File2 file 1 is newer than file 2
Test File1-ot File2 file 1 is older than file 2
The test-b File file exists and is a block device file
Test-c File file exists and is a character device file
The test-d File file exists and is a directory
Test-e File file exists
Test-f File file exists and is a regular file
The test-g File file exists and the group ID is set
Test-G File file exists and belongs to valid group ID
The test-h File file exists and is a symbolic link (same as-L)
The test-k File file exists and the sticky bit is set
The test-b File file exists and is a block device file
Test-L File file exists and is a symbolic link (same as-h)
The test-o File file exists and belongs to a valid user ID
The test-p File file exists and is a named pipe
The test-r File file exists and is readable
The test-s File file exists and is a socket
The test-t FD file descriptor is opened at a terminal and reproduced. Please indicate the article.
Command line inner loop:
Do echo 0 & & while [$a-lt 10]; do echo $a & & a = `expr $a + 1`; done
At this point, the study of "script statement syntax commonly used in linux shell" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.