In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what is shell script in linux", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is shell script in linux" this article.
In fact, shell script is the use of shell function abbreviation of a program, this program is the use of plain text files, some shell syntax and commands (including external commands) written inside, with regular expressions, pipe commands and data stream redirection and other functions to achieve our desired purpose.
The difference between two different ways of executing bash:
# source sh02.sh
In this way, the shell script is executed in the parent process, sharing a shell environment and variables, and all configuration files such as ~ / .bashrc can be updated with source ~ / .bashrc without logging out of the system.
# sh sh02.sh
In this way, sh02.sh is executed in the child process, and its variables are not visible to the parent process, and the variables in the parent process are not visible to the child process, but it is common to use export to change the variable into an environment variable.
Use test to judge
The logo of the test represents the meaning of 1. About the "file type" judgment of a file, such as test-e filename indicates whether it exists-e whether the "file" exists? (commonly used)-f does the "file" exist and is a file (file)? (common)-d does the "file" exist and is a directory (directory)? (commonly used)-b does the "file" exist and is a block device device? -c does the "file" exist and is a character device device? -S does the "file" exist and is a Socket file? -p does the "file" exist and is a FIFO (pipe) file? Does the "file" exist and is a connection file? two。 With regard to the permission detection of a file, for example, test-r filename indicates whether it is readable (but there are often exceptions to root permissions)-r detects whether the file exists and has "readable" permission? -w detects whether the file exists and has "writable" permission? -x detects whether the file exists and has "executable" permission? -u detects whether the file exists and has the attribute of "SUID"? -g detects whether the file exists and has the attribute of "SGID"? -k detects whether the file exists and has the attribute of "Sticky bit"? -s detects whether the file exists and is a "non-blank file"? 3. The comparison between two files, such as: test file1-nt file2-nt (newer than) to judge whether file1 is newer than file2-ot (older than) to judge whether file1 is older than file2-ef to judge whether file1 and file2 are the same file, can be used to judge hard link. The main significance is to determine whether the two files point to the same inode! 4. On the decision between two integers, for example, test N1-eq n2-eq is equal (equal)-ne is equal (not equal)-gtn1 is greater than N2 (greater than)-ltn1 is less than N2 (less than)-gen1 is greater than or equal to N2 (greater than or equal)-len1 is less than or equal to N2 (less than or equal) 5. Test-z string determines whether the string is empty, truetest-n string determines whether the string is not empty, and true if it is not empty.
Note:-n can also omit test str1 = str2 to determine whether str1 is equal to str2, if equal, return truetest str1! = str2 to determine whether str1 is not equal to str2, if equal, return false6. Multiple conditions are determined, for example: test-r filename-a-x filename-a (and) two conditions hold at the same time! For example, test-r file-a-x file, true is returned only when file has both r and x permissions. -o (or) either of them is established! For example, test-r file-o-x file, if file has r or x permissions, true can be sent back. ! Reverse state, such as test!-x file, which returns true when file does not have x
You can also use [] to make a judgment. However, one thing to note is:
1. Each component must be divided by a space bar in parentheses []
2, variables in square brackets are best enclosed in double quotation marks (not when variables are defined)
3, constants in square brackets, preferably enclosed in single or double quotation marks
= = the default variable for shell script ($0. 1.) )
/ path/to/scriptname opt1 opt2 opt3 opt4
$0 $1 $2 $3 $4
That's clear enough.
In addition to these numeric variables, there are several special:
* $#: represents the "number" of the following parameters
* $@: stands for "$1", "$2", "$3" and "$4". Each variable is independent (enclosed in double quotes)
* $*: stands for "$1c$2c$3c$4c", where c is a split character and defaults to a space, so in this case it stands for "$1 $2 $3 $4"
= = conditional judgment if... Then... Fi
Typical examples:
The code is as follows:
If ["$yn" = = "Y"] | | ["yn" = = "y"]; then
Echo "OK"
Exit 0
Fi
Take advantage of case... Esac to judge =
Case $variable name in
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.