Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case Analysis of shell if judgment sentence

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor will share with you the relevant knowledge points of shell if judgment sentence example analysis, the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Comparative character writing in UNIX Shell

-eq equals;-ne does not equal

-gt is greater than;-lt is less than

-le less than or equal to;-ge greater than or equal to

-z empty string;-n non-empty string

= two characters are equal;! = two characters are not equal

No matter what programming language is inseparable from conditional judgment. SHELL is no exception.

The general format is as follows:

If list thendo something hereelif list thendo another thing hereelsedo something else herefi is basically the same as any other scripting language. There's not much difference. But it's worth noting that. [] the judgment of the conditions inside. The explanation is as follows: 1 string judgment

Str1 = str2

True str1! = str2 when two strings have the same content and length

True-n str1 when strings str1 and str2 are not equal

True (string is not empty)-z str1 when the length of the string is greater than 0

True (empty string) str1 when string length is 0

True when string str1 is not empty

The judgment of 2 numbers

Int1-eq int2

The equality of two numbers is true int1-ne int2

Two numbers are not equal to true int1-gt int2

True int1-ge int2 if int1 is greater than int2

Int1 greater than or equal to int2 is true int1-lt int2

True int1-le int2 if int1 is less than int2

True that int1 is less than or equal to int2

3 if judgment condition statements related to files

-r file

User readable as true-w file

User can write as true-x file

User executable is true-f file

File is regular file is true-d file

File is directory is true-c file

The file is a character and the special file is true-b file

The file is a block and the special file is true-s file

True if the file size is non-0-t file

True when the device specified by the file descriptor (default is 1) is a terminal

4 complex logic judgment

-an and-o or! Non

Although the syntax is simple, it can implement powerful functions or execution logic when used in SHELL.

The above is all the content of this article "shell if judgment sentence example Analysis". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report