In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the IF judgment conditions under linux". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
UNIX shell comparison characters written:
-eq equals-ne does not equal-gt greater than-lt less than-le less than or equal to-ge greater than or equal to-z
Empty string = two characters equal!= Two characters unequal-n non-empty string
No matter what programming language, conditional judgment is indispensable. Shell is no exception.
if list thendo something hereif list thendo another thing heresedo something else herefi
An example:
#!/ bin/shSYSTEM=`uname -s` #Get the operating system type, my local is linuxif [ $SYSTEM = "Linux" ] ; then #If linux output linux string echo "Linux"elif [ $SYSTEM = "FreeBSD" ] ; thenecho "FreeBSD"elif [ $SYSTEM = "Solaris" ] ; thenecho "Solaris"elseecho "What? "fi #judgment ends with fi
It's basically the same as any other scripting language. Not much difference. However, it is worth noting that. […] the judgment within. The description reads as follows:
1 string judgment
str1 = str2
True if two strings have the same content and length str1 != str2
true if str1 and str2 are unequal-n str1
True if string length is greater than 0 (string is not empty) -z str1
True when string length is 0 (empty string) str1
True when string str1 is non-empty
2 Number of Judgments
int1 -eq int2 is true
int1 -ne int2 is true
int1 -gt int2 int1 is greater than int2 is true
int1 -ge int2 int1 is greater than or equal to int2 is true
int1 -lt int2 int1 less than int2 is true
int1 le int2 int1 less than or equal to int2 is true
3 If conditional statements related to files
-r file User readable is true
-w file user can write true
-x file user executable is true
-f file file is true for regular files
-d file is true for directory
-c file file is character special file is true
-b file file is block special file is true
-s file True if file size is non-zero
-t file True when the device specified by the file descriptor (default 1) is terminal
4 Complicated logic judgments
-a and-o or! non
The syntax is simple, but when used in SHELL, it can implement powerful functionality or execute logic.
"What are the IF judgment conditions under linux" is introduced here. Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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.