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

How to use shell conditional judgment statement in linux

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

How to use shell conditional judgment sentence in linux, aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Common system variables

$0 name of the current program

The nth parameter of the current program, natively 1pm 2, … nine

* any parameters of the current program (excluding the program itself)

$# number of parameters of the current program (excluding the program itself)

$PID of the current program

$! The PID that executed the previous instruction (seems to work?)

$? The return value of executing the previous instruction

Conditional judgment: expression is a string operation

Whether the n str string str is not empty

Whether the z str string str is empty

Str1 = whether str2 str1 is the same as str2

Whether str1 is different from str2 in str2 str1

Conditional judgment: expression is an integer operation

Expr1-an expr2 is true if expr1 and expr2 are evaluated as true

Expr1-o expr2 true if expr1 or expr2 is evaluated as true

Conditional judgment: expression is a bool operation

Int1-eq int2 true if int1 equals int2

Int1-ge int2 is true if int1 is greater than or equal to int2

Int1-gt int2 true if int1 is greater than int2

Int1-le int2 is true if int1 is less than or equal to int2

Int1-lt int2 true if int1 is less than int2

Int1-ne int2 true if int1 is not equal to int2

Conditional judgment: expression is a document operation

-b whether the block document-p document is a named pipe

-whether c is a character document-whether the r document is readable

-d whether a directory-s document length is not zero

Whether the-e document exists-whether S is a socket document

-f is a normal document-x document is executable, then true

-g whether the SGID bit of the document is configured-u whether the SUID bit of the document is configured

True if the-G document exists and any-w documents that belong to the group are writable

Whether the k document is configured with paste bits-whether t fd fd is an open document descriptor connected to the terminal (fd defaults to 1)

-whether the O document exists and belongs to any of the user

This is the answer to the question about how to use shell conditional judgment sentence in linux. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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

Servers

Wechat

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

12
Report