Linux built-in commands and linux creation commands

Source: Internet
Author: User
Tags autoload builtin echo command

Linux built-in commands and linux creation commands
Built-in commands

Built-in commands are included in the Bash tool set. This mainly takes into account the execution efficiency issue-the built-in commands will be executed faster than the external commands, external commands usually need to fork a separate process for execution. Another reason is that a specific built-in command requires direct access to the shell kernel.

A built-in command is usually the same as a system command, but Bash implements these commands internally. For example, Bash's echo commands and/bin/echo are different, although their behavior is the same in most cases.
Keywords mean reserved words. For shell, keywords have special meanings and are used to build the shell syntax structure.
For example, "for", "while", "do", and "!" All are keywords. Like built-in commands, keywords are also the backbone of Bash. However, unlike built-in commands, keywords are not commands, but part of a relatively large command structure.

I/O class
Echo
Importance: high
Print (to stdout) an expression or variable.
Echo needs to use the-e parameter to print escape characters.
Generally, each echo command starts a new line on the terminal, but the-n option will block the new line.
Note: echocommandAny line breaks generated by commands will be deleted.
$ IFS (internal domain separator) generally contains \ n (line break) in its blank character set. Bash separates command output based on the line feed in the parameter. Echo then outputs the parameters with spaces instead of line breaks.
Note: This command is a built-in shell command. It is different from/bin/echo, although its behavior is similar.

Printf
Importance: Medium
The printf command, formatted output, is an enhancement of the echo command. It is a limited deformation of the C-language printf () library function, and it is somewhat different in syntax.
The main application that uses printf is to format the error message.

Read
Importance: high
Read the value of a variable from stdin, that is, obtain the value of the variable through interaction with the keyboard. Use the-a parameter to obtain the array.
For the read command, the-n option does not detect the ENTER (New Line) Key.
The-t option of the read command allows you to set the read timeout value.
The read command can also read the variable value from the redirected file. If the file contains more than one row, only the first row is allocated to this variable. If the read command has more than one parameter, each variable gets a string separated by a defined blank space from the file as the value of the variable.

File System
Cd
Importance: high
Cd directory modification command

Pwd
Importance: high
Print the current working directory. This will give the user (or script) the current working directory. The result of using this command is the same as the value read from the built-in variable $ PWD.

Pushd, popd, dirs
Importance: low
These commands can make the working directory bookmarks, that is, you can move the working directory forward or backward in order.
You can save the working directory list for the stack-pressing action. You can perform different operations on the directory stack.
Pushd dir-name pushes the path dir-name to the directory stack and modifies the current directory to dir-name.
Popd pops up the top directory in the directory stack and modifies the current directory to the directory that pops up.
Dirs lists the contents of all directory stacks (compared with $ DIRSTACK ). A successful pushd or popd will automatically call the dirs command.

Variable class
Let
Importance: Medium
The let Command performs arithmetic operations on the variables. In many cases, it is regarded as a simplified version of the complex expr version.

Unset
Importance: Medium
The unset command is used to delete a shell variable. The result is to set this variable to null.

Export
Importance: Medium
The export Command makes export variables available in all sub-processes of the script (or shell.
Unfortunately, there is no way to export the variable to the parent process (that is, the process that calls this script or shell.
An important use of the export command is used in the startup file. The Startup File is used to initialize and set environment variables so that user processes can access the environment variables.

Getopts
Importance: Medium
It can be said that this is the most powerful tool for analyzing the command line parameters passed to the script. This command is the same as the external getopt command, which is used by the library function getopt in C language. It allows multiple options to be passed and connected to the script, and
Configure multiple parameters to the script.
The getopts structure is usually composed of a group in a while loop. Each time an option and parameter are processed during the loop process, the value of the Hidden variable $ OPTIND is added, and the next processing is performed.
Note: 1. A minus sign (-) must be added before the parameter passed to the script through the command line (-). This is a prefix, so the getopts command will regard this parameter as an option. In fact, getopts does not process parameters without the "-" prefix. If the first parameter does not have "-", the processing of the option will end.
2. The while LOOP Template Using getopts is somewhat different from the standard while loop template. There is no [] Judgment condition in the standard while loop.
3. The getopts structure replaces the getopt external command.

Script Behavior
Source,. (point command)
Importance: high
When this command is executed on the command line, a script is executed. A source file-name file in a file will load the file-name file. A source file (or a dot command) will introduce code in the script and attach it to the script (same effect as the # include command in C ). The final result is like inserting the content of the corresponding file on the "sourced" line, which is useful when multiple scripts need to reference the same data or function libraries.

Exit
Importance: high
Absolutely stop a script. The exit command can find an integer variable as the exit code when the exit script returns the shell. Using exit 0 is a good habit for exiting a simple script and indicates that the script runs successfully.
NOTE: If exit is used without parameters, the exit code is the exit code of the last command in the script. It is equivalent to exit $ ?.

Exec
Importance: Medium
This shell built-in command replaces the current process with a specific command. Generally, when a shell runs a command, it fork off a sub-process to run the command. By using the exec built-in command, shell will not fork, and the execution of the command will replace the current shell. Therefore, when we use it in a script,
It will force exit the script.

Ture
Importance: high
A command that returns a successful exit code (that is, returns 0), but does nothing else.

Type [cmd]
Importance: Medium
Similar to the which extension command, type cmd provides the complete path of "cmd. Unlike the which command, the type command is a Bash built-in command. A very useful option is-a. This option can be used to identify whether the recognized parameter is a keyword or a built-in command, or to locate a system command with the same name.

Bind
Importance: low
Bind built-in commands are used to display or modify the Key Binding of readline [5.

Help
Importance: Medium
Get a small usage Summary of shell built-in commands. This is similar to the whatis command, but the help Command is a built-in command.

Job control commands
Jobs
Importance: Medium
List all running jobs in the background and give the job number.

Disown
Importance: Medium
Delete a job from the current table of shell jobs.

Fg, bg
Importance: Medium
The fg command can run a job running in the background on the foreground. The bg command restarts a suspended job and runs it in the background. If the job number is not specified when you use the fg or bg command, operations are performed on the currently running job by default.

Wait
Importance: Medium
Stop the script until all the jobs running in the background are completed, or until the job with the specified job number or process number as the option ends.
You can use the wait command to prevent the script from exiting before the background job is completed (this will generate an orphan process.

Logout
Importance: Medium
You can also specify an exit code to exit a logon shell.

Times
Importance: Medium
The time occupied by the command execution is provided and output in the following format:
0m0. 020 s 0m0. 020 s
This is a very limited capability, so it is not often used in shell scripts.

Kill
Importance: high
Forces a process to end by sending an appropriate end signal.

Command
Importance: Medium
The command disables searching for aliases and functions. It only looks for internal commands and scripts or executable programs found in the search path.

Note the priority of bash commands:
1. Alias
2. Keywords
3. Functions
4. built-in commands
5. script or executable program ($ PATH)

Builtin
Importance: low
The command after "builtin" will only call the built-in command. Temporarily disable functions with the same name or extension commands with the same name.

Enable
Importance: low
This command can be used to disable or resume built-in commands. For example, enable-n kill will disable the built-in kill command. Therefore, when we call kill, the external command/bin/kill will be used.
-Option a restores the corresponding built-in commands. If no parameters are provided, all built-in commands are restored.
Option-f filename loads a built-in command in the form of a shared library (DLL) from the appropriate compiled target file [6.

Autoload
Importance: low
This is transplanted from the autoloader command of ksh. A function with the "autoload" declaration is loaded only when it is called for the first time. This will save system resources.
Note: the autoload command is not part of the core command during Bash installation. This command needs to be loaded using the command enable-f (see the above enable command.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.