In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what bash is in linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Any interface that can operate an application can be called shell. In a narrow sense, shell refers to command-line software, including bash. In a broad sense, shell includes graphical interface software, because the graphical interface can also operate a variety of applications to invoke kernel work, but here we mainly refer to bash.
# type [- tpa] command-> check whether the command is built-in or external to bash
* use $var or ${var} to obtain the value of the variable var
* double quotation marks in bash: special characters such as $can retain the original features.
* single quotation marks in bash: all characters are ordinary characters with no other meaning
* you can use\ to change special characters into general characters.
* you can use $(other commands) to nest the return values of other commands in the command, that is, ${var} gets the value of the variable var, and $(command) gets the return value of the command
* if the variable needs to be executed in other child processes, export var is required to make the variable an environment variable
* unset var can undefine the variable var
= environment variable =
# env-> View the environment variables of the current system
$itself is also a variable that represents the PID number of this shell, such as # echo $$outputs the PID of this shell
? Ability is also a variable that represents the return value of the last executed command. Generally, a 0 indicates success, and a non-0 indicates a problem.
Common language coding setting: / etc/sysconfig/i18n
# read [- pt] variable-> Keyboard reads variable input values
-p: can be followed by a prompt
-t: the number of seconds you can wait for later, instead of waiting for user input
Declaration of variable =
# declare [- aixrp] var
-a: define the following var as an array type
-I: define the following var as the integer integer type
-x: use the same as export, but change the following var into an environment variable
-r: set the variable var to readonly state, which cannot be changed or reset
-p: list the types of variables separately
If you change-to + to cancel the operation
= restrict the use of computer resources by users
# ulimit [- SHacdfltu] [quota]
-H:hardlimit, a strict limit, must not exceed this value.
-S:softlimit, you can exceed this value, but there is a warning message
-a: list all limits without any parameters.
-c: when something goes wrong, the system will write the information of the process in memory into a file, which is called the kernel file. Limit the maximum capacity of each kernel file
-f: the maximum single file capacity that can be created by this shell, in KB
-d: the maximum amount of memory that a process can use
-l: the amount of memory available for lock
-t: maximum CPU time (in seconds)
-u: maximum number of processes (process) that can be used by a single user
Deletion and replacement of variable contents
# echo ${path#/*:}-> Delete the first one in the path variable that begins with / and ends with:
# echo ${path##/*:}-> Delete the longest one, that is, only the last path is retained
#-> the shortest one that matches the replacement text
# #-> the longest one that matches the replacement text
If you want to delete it from the back, replace # with%
Next, let's talk about the replacement function:
# echo ${path/sbin/SBIN}-> replace the first sbin with SBIN
# echo ${path//sbin/SBIN}-> replace all sbin with SBIN
Let's summarize this part and explain it as follows:
Description of variable setting method ${variable # keyword}
${variable # # keyword} if the data starting from scratch in the variable content meets the "keyword", the shortest data will be deleted
If the data starting from the beginning of the variable content matches the "keyword", the longest data will be deleted ${variable% keyword}
${variable% keyword} if the data from the tail to the front of the variable content matches the keyword, the shortest data will be deleted
If the data before the end of the variable content matches the "keyword", the maximum matching data is deleted ${variable / old string / new string}
${variable / / old string / new string} if the variable content matches the "old string", "the first old string will be replaced by the new string"
If the content of the variable matches the "old string", all the old strings will be replaced by the new string. "
# username=$ {username:-root}-> take the original value if the username is not empty, and set it to root if it is not set or an empty string
The bash login interface and the welcome screen after successful login
Tips: it's best to log in to a single bash, and then use job control to switch between different jobs, so that the history of shell can be completely preserved.
Search path order of command execution: first alias, then builtin, then $PATH
Bash login interface configuration file: / etc/issue, remote login interface configuration file: / etc/issue.net
Command # man mingetty to see the meaning of each code in issue
Configuration file of information displayed after successful login: / etc/motd
= = bash environment variable =
Configuration file for login shell:
/ etc/profile: system global configuration file, it is best not to modify this file
~ / .bash_profile or ~ / .bash_login or ~ / .profile: user-defined bash profile
~ / .bashrc, which is read by both login shell and non-login shell
= wildcards and special characters in bash =
Symbolic meaning * represents any character "0 to infinitely many"? For "there must be a" arbitrary character [] also means "there must be a character in parentheses" (not an arbitrary character). For example, [abcd] stands for "there must be one character, which could be any of the four" [-] if the minus sign is in the middle brackets, it stands for "all characters in the coding order". For example, [0-9] represents all numbers between 0 and 9, because the language codes of numbers are continuous! [^] if the first character in parentheses is an exponential symbol (^), it means "reverse selection". For example, [^ abc] means that there must be a character, which is accepted as long as it is not a, b, c character.
Apart from wildcards, what are the special symbols in the bash environment? Let me put it together first:
Symbol content # comment symbol: this is the most commonly used in script, which means that the following statements do not execute\ jump symbols: restore "special characters or universal characters" to general characters | pipe: the definition of separating two pipe commands (the last two sections are prefaced); successive instructions are issued delimiters: the definition of continuous commands (note! (different from the pipe command) ~ the user's home directory $takes the variable prefix: that is, the variable substitution value that needs to be added before the variable & work control (job control): turn the instruction into working in the background! The meaning of "not" not in the sense of logical operation! / directory symbol, path division symbol >, > > data stream redirection: output orientation, respectively "replace" and "accumulate"
> means to add after emptying, > > means to add up and append. understand? O (╯□╰) o
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.