In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "what are the similarities and differences between Shell strings". In daily operation, I believe many people have doubts about the similarities and differences between Shell strings. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what are the similarities and differences between Shell strings?" Next, please follow the editor to study!
#! / bin/sh# tests various string comparison operations. In # shell, the difference between adding single quotation marks to the value of a variable, refreshing quotation marks and not adding them: it is irrelevant to the type, that is, it does not add quotation marks to become a string type, and # single quotation marks do not replace related quantities, such as not interpreting the $symbol as a variable reference, thus replacing it with the value of the corresponding variable. The double quotation marks replace the original value entered by # author:tenfyguoA= "$1" B = "$2" echo "# to determine whether the string is equal to if [" $A "=" $B "] Thenecho "[=]" fi# determines whether the string is equal or not, which is equivalent to the above = if ["$A" = = "$B"]; thenecho "[=]" fi# Note: the function of = = behaves differently in [[]] and [], as follows # if $a starts with "a" (pattern match), it will be true if [["$A" = a *]] Thenecho "[= = a *]]" fi# if $an equals a * (character match), then the result is trueif [["$A" = = "a *"]] Thenecho "= /" aweed / "" fi#File globbing (wildcard) and word splitting will occur, and the a* will automatically match to the corresponding file that starts with a. # if there is a file in the current directory: add_crontab.sh, the following output ok#if ["add_crontab.sh" = = a*]; then # echo "ok" # fiif ["$A" = = a*] Thenecho "[= a *]" fi# if $an equals a * (character match), then the result is trueif ["$A" = = "a *"]; thenecho "= /" averse / "" fi# string is not equal if ["$A"! = "$B"]; thenecho "[! =]" fi# string is not equal if [["$A"! = "$B"]] Thenecho "[! =]]" fi# string is not empty, length is not 0if [- n "$A"]; thenecho "[- n]" fi# string is empty. That is, the length is 0.if [- z "$A"]; thenecho "[- z]" fi# needs to be escaped, otherwise it is considered to be a redirect symbol if [$A / > $B]; thenecho "[>]" fiif [[$A >]; thenecho "[>]" fi so far, the study on "what are the similarities and differences between Shell strings" is over, hoping to solve everyone's 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.