In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the shell script-related issues, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Shell: interpret and execute user input commands, explain them line by line, or batch many instructions. You can write all these instructions into one script file and let shell execute more than one command at a time, the commonly used shell (bash, which assumes the role of shell, is the shell script interpreter, is an executable binary file).
The execution process of shell:
After a user enters a command on the command line, Shell usually forks the child process and calls exec to replace the program, allowing its grandchild process to execute the command, but the built-in command of Shell is an exception. Executing the built-in command is equivalent to calling a function in the Shell process and does not create a new process. Commands such as cd, export, umask and exit are built-in commands.
Specific steps:
1. The interactive Shell (bash) fork/exec a child Shell (sh) is used to execute the script, and the parent process bash waits for the child process sh to terminate.
2.sh reads cd in the script.. Command, call the corresponding function to execute the built-in command, and change the current working directory to a higher-level directory.
3.sh reads the ls command in the script, fork/exec this program, lists the files in the current working directory, and sh waits for ls to terminate.
After 4.ls terminates, sh continues to execute, reading to the end of the script file, sh terminates.
After 5.sh terminates, bash continues execution and prints a prompt waiting for user input.
Eval: is a normal command line typed on the terminal. However, when you put eval in front of it, the result is that shell scans it twice before executing the command line
Usage: eval [parameters] eval can read a series of parameters, and then execute them according to the characteristics of the parameters themselves.
Parameter: scan it twice before the parameter line, and calculate the content of the parameter again.
1. Used to echo simple variables:
two。 Two scans for displaying complex variables, create a new text file, and display the contents of the text file
3. You can get the last parameter
4. Create a pointer variable with eval, and you can also change the content of the space the pointer refers to.
Eval: function processing results cannot be obtained. The processing results of all commands and functions can only be obtained through ``. Eval nesting is meaningless and can be executed through eval (eval ("code")) in other languages (performing the return of dynamically generated code). Because eval in shell simply executes the following eval commands as a command string, it loses the nesting effect and is replaced by command substitution.
The difference and relation between ``and $()
1. In some cases they are used the same way, but there are differences between them
As in the example above, they get the same value when showing the current time, but when they get the home directory of the current directory, ``converts the special meaning of $, but it is not explained when using $() and is escaped into an ordinary character by\.
two。 If you add another / to the above example
$() is escaped into a string and the contents are interpreted inside.
3. Write the following in the test.sh script
As above, four backslashes are interpreted as one when using backquotes and two when $() is used.
4. When using multiple backslashes
It can be obtained from the above: the backquote itself escapes\ and retains its own meaning. if you want to play the special meaning of\ in the backquote, you must use two\ to indicate that $() is used as usual.
The difference and relation between [test command] and [[]]
1. [is an executable program
two。 The single bracket TEST command separates the variable from the word. When the value of the variable contains a blank character, the variable is enclosed in quotation marks, while the double bracketed TEST command does not separate the word from the variable.
When testing, the bash response parameters are too many, because the single quotation mark TEST command separates the words from the variables, and the result is
[hello world = "hello world"], adding the string hello becomes a comparison between the string world and the string hello world. So if the variable of the TEST command in single parentheses contains spaces, but it still has to be compared to a string, you must put double quotation marks on the variable so that it will not have an error. The TEST command in parentheses below does not separate variable words.
3. The single parenthesis TEST command does not extend the SHELL metacharacter, while the double parenthesis TEST command extends the SHELL metacharacter.
4. In a double-bracketed TEST command, a string (with or without spaces) must also be enclosed in quotation marks if it is only in the expression as a normal string, not as part of a pattern. If a string value (the one on the right) is not in double quotation marks, then the string is a pattern, and if it contains SHELL metacharacters, BASH will extend it. If a string is in double quotation marks, it is a very ordinary string, even if the string contains special characters, that is, it is treated as normal content.
5. [express1-an express2] this is the TEST command in single parentheses, because simple ones do not support metacharacter extension, so they can only be called expressions, which can be combined to form a logical test.
Thank you for reading this article carefully. I hope the article "what are the problems related to shell scripts" shared by the editor will be helpful to you? at the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.