Built-in commands for Bash shell
1. (View command properties) type [-TPA] name: When no arguments are added, the external command or Bash internal command is displayed
-T:
File: Represented as an external command
Alias: Command for command aliases set by this command
Builtin: This command is a command feature built into bash
-P: If you follow the name command, the full file name (external command) is displayed or the built-in command is displayed
- A: In the path defined by the path variable, list all commands containing the name, including the alias
2. Getting and setting variables:
1. Use echo to get the variable name (before adding $)
Eg:echo $PATH
2. Setting variables
Name=value
Precautions:
A. Connecting variables to variables with "="
B. Cannot directly connect the space symbol on either side of the equal sign
C. Variable names can only be English letters and numbers, cannot start with a number
D. If there is a space character, the double quotation mark "" "or the single quotation mark" ' "to use to combine the contents of the variable, but the double quotation marks in the
Special characters can preserve the properties of a variable, but special characters in single quotes are only ordinary characters
E. If necessary, the escape character "\" becomes a general symbol (such as enter,$,\, whitespace, '), etc.
F. If the variable is an extension variable, double quotes and the $ variable name, such as "$PATH":/Home "continue to accumulate the content
G. If a variable needs to be executed in another subroutine, you need to export the variable into an environment variable, such as export PATH;
H. How to cancel a variable: unset variable name
3. Functions of the environmental system
A. Description of environment variables: env (enviroment abbreviation) to view all environment variables in the current shell environment
B. Other variables that are valid in the shell environment
4. Important Variable Settings
A.PS1 (setting of the prompt)
-\d: Represents the date format as "Day of the Week"
-\h: Full host name
-\h: Take the first name of the host only
-\t: Display 24-hour format time, HH:MM:SS
-\t: Display 12-hour format time, HH:MM:SS
-\u: Displays the current user name
-\v:bash Version Information
-\w: Full working directory name, home directory meeting ~ Replace
-\w: Using basename to get the working directory name, the last directory name is displayed
-\#: The first few commands to execute
-\$: Execution terminator, root user ends with #, otherwise $
Eg:ps1= ' [\[email protected]\h \w \ t #\#]\$ '
will be displayed [[email protected]/root 15:23:23 #23]#
5. Converting a custom variable to an environment variable: Export
Defining variables Xxxx=linux
Convert to environment variable export xxxx
Query All environment variables export to find your definition of xxxx at the bottom
of the
3. Variable keypad reading, array and declaration: Read,array,declare
1.read [-PT] Variable
-P: Follow-up prompt
-T: The number of seconds that can be followed to wait, not waiting for the user
1.eg: stored in variable vt1 via keyboard input
[Email protected] ~/desktop 15:32:24 #28] #read VT1
Falkfjakfhruh
[[email protected] ~/desktop 15:32:43 #29] #echo $VT 1
Falkfjakfhruh
[Email protected] ~/desktop 15:32:54 #30]#
2. Prompt user to input content into variable vt2 within 20 seconds
[Email protected] ~/desktop 15:35:51 #33] #read-p ' input your words within seconds: '-t VT2
Input your words within SECONDS:FAJJFAHUFHEFHAHFEUHFA
[[email protected] ~/desktop 15:36:09 #35] #echo $VT 2
Fajjfahufhefhahfeuhfa
[Email protected] ~/desktop 15:36:15 #36]#
2.declare/typeset: Declaring variable properties
DECLARE-[AIXR] Variable
-A: Defines the variable as an array
-I: Define variable As Integer numbers
-X: As with export, define variable as an environment variable
-r: Defines variable as a read-only object, cannot change content, and cannot cancel objects
3. Array Property Description
Var[index] = Content
EG:VAR[1] = "Good Day"
Var[2] = "Nice Day"
var[3]= "Happy Great Day"
Display array: echo "${var[1]}, {var[2]}, {var[3]}"
4. Limitations related to file systems and programs: Ulimit
Cause: Using bash can limit the system resources of some users (including the number of open files, the CPU time used, and the total amount of memory used)
The format is as follows: Ulimit-[SHACDFLPTU]
-h:hard limit is strictly limited, must not exceed the set value
-s:sot Limit warning limits, can exceed this value, but there will be warnings
-A: List all limits
-C: Maximum core file capacity to build
-D: Maximum capacity that program data can use
-F: The maximum file size that this shell can establish (typically 2G), in kilobytes
-L: Amount of memory that can be user locked (lock)
-P: Quantity available for piping (pipe)
-T: Maximum CPU time that can be used (s)
-U: The maximum number of processes (process) that a single user can use
Eg:1. List all restricted data
Ulimit-a
2. Set other users to create new file size within 1M
Ulimit-f 1024
5. Setting function of additional variables
How variables are set |
When STR is not set |
When Str is an empty string |
When STR is set to a non-empty string |
VAR=${STR-EXPR} |
var=expr |
Var= |
var= $str |
VAR=${STR:-EXPR} |
var=expr |
var=expr |
Var= $str |
VAR=${STR+EXPR} |
var=expr |
var=expr |
var=expr |
VAR=${STR:+EXPR} |
var=expr |
var= |
var=expr |
VAR=${STR=EXPR} |
str=expr var=expr |
STR does not change var= |
STR does not change Var= $str |
VAR=${STR:=EXPR} |
str=expr var=expr |
str=expr var=expr |
Var= $str |
VAR=${STR?EXPR} |
Expr loses to stderr |
Var= |
Var=str |
VAR=${STR:?EXPR} |
Expr loses to stderr |
Expr loses to stderr |
Var=str |
6. Command aliases and History commands
A.alias cls= "clear"
B.hostory
N: Lists the most recent n-line commands
-C: Clears all commands in the current shell command
-A: Add the current New History command to Histfiles, and if you do not join the Histfiles, add the default ~/.bash_history
-R: Reads the contents of the histfiles into the history of the current shell
-W: Writes the current history to Histfiles
Supplemental command: a.! Number: Re-executes the number in history command
B.! Command: the commands that are searched forward by the most recent command "command string starts with" and perform
c.!! : Executes the previous command
Linux simple command--shell Getting Started command