Linux built-in commands

Source: Internet
Author: User
Tags autoload aliases builtin echo command

Built-in commands

The built-in command refers to the commands contained within the Bash toolset. This is mainly due to the problem of execution efficiency-the built-in command will execute faster than external commands, and external commands often need to fork out a separate process to execute. Another reason is that a specific built-in command requires direct access to the Shell kernel section.

A built-in command typically has the same name as a system command, but Bash internally re-implements the commands. For example, Bash's echo commands are not the same as/bin/echo, although their behavior is the same in most cases.
The keyword means reserved words. For the shell, the keyword has a special meaning and is used to construct the shell's grammatical structure.
For example, ' for ', ' while ', ' Do ' and '! ' are all keywords. As with the built-in command, the keyword is also the backbone of Bash, but unlike the built-in command, the keyword itself is not a command, but rather a part of a larger command structure.

I/O class
Echo
Degree of importance: high
Print (to stdout) an expression or variable.
Echo needs to print the escape character using the-e parameter.
Each echo command in general will have a new line on the terminal, but the-N option will block the new row.
Note: Echo command will remove any line breaks that have a command.
The $IFS (internal domain delimiter) typically contains \ n (newline characters) in its white-space character set. Bash therefore separates the output of the command according to the line breaks in the parameter. Echo then outputs these parameters with a space instead of a newline.
Note: This command is a built-in command of the shell, unlike/bin/echo, although behaves similarly.

Printf
Degree of importance: Medium
The printf command, formatted output, is an enhancement of the echo command. It is a finite variant of the C-language printf () library function, and is somewhat different in syntax.
The most important application to use printf is formatting error messages.

Read
Degree of importance: high
Reads the value of a variable from the stdin, which is the value of the variable obtained by interacting with the keyboard. An array can be obtained using the-a parameter.
For the read command, the-n option will not detect the Enter (new row) key.
The-t option of the Read command allows you to set the timeout value for read.
The read command can also read the value of a variable from a redirected file. If the contents of the file exceed one line, only the first row is assigned to the variable. If the read command has more than one parameter, then each variable takes the defined white space delimited string from the file as the value of the variable.

File System Classes
Cd
Degree of importance: high
CD Modify Directory command

Pwd
Degree of importance: high
Prints 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 level: Low
These commands allow the working directory to be bookmarked, which means that the working directory can be moved forward or backward sequentially.
The action of the stack can save the working directory list. option allows different operations to be made on the directory stack.
pushd Dir-name pushes the path dir-name into the directory stack and modifies the current directory to Dir-name.
POPD pops the topmost directory in the directory stack and modifies the current directory to the pop-up directory.
Dirs Lists the contents of all directory stacks (compared to $DIRSTACK). A successful pushd or POPD will automatically invoke the Dirs command.

Variable class
Let
Degree of importance: Medium
The Let command executes the arithmetic operation of the variable. In many cases, it is seen as a simplified version of the complex versions of expr.

unset
Degree of importance: Medium
The unset command is used to delete a shell variable, and the effect is to set the variable to null.

Export
Degree of importance: Medium
The export command will make the export variable available in all the child processes of the running script (or shell).
Unfortunately, there is no way to export the variable to the parent process (that is, the process that invokes the script or shell).
An important use of the Export command is in the startup file, which is used to initialize and set the environment variables so that the user process can access the environment variables.

Getopts
Degree of importance: Medium
This can be said to be the most powerful tool for parsing command-line arguments passed to the script. This command is the same as the getopt external command, and the library function getopt in the C language. It allows multiple options to be passed and connected to the script, and can be divided into
With multiple parameters into the script.
The getopts structure usually consists of a set of one while loop, each processing an option and parameter at a time, then increasing the value of the implied variable $OPTIND, and then the next processing.
Note: 1. A minus sign (-) must precede the arguments passed to the script by the command line. This is a prefix so that the getopts command will assume that this parameter is an option. In fact, Getopts does not handle parameters without the "-" prefix, and if the first parameter does not have "-", then the processing of the option is ended.
2. Using the getopts while loop template is somewhat different from the standard while loop template. There are no criteria for judging [] in a standard while loop.
The 3.GETOPTS structure will replace the getopt external command.

Script behavior
Source,. (Point command)
Degree of importance: high
When this command executes on the command line, a script is executed. A source file-name will load the File-name file within a file. Source a file (or Point command) will introduce code into the script and attach it to the script (the same effect as the #include directive in C). The end result is like inserting the contents of the corresponding file on the "sourced" line, which is useful when multiple scripts need to reference the same data, or a library of functions.

Exit
Degree of importance: high
Absolutely stop a script from running. Exit command There is an exit code that can be arbitrarily searched for an integer variable as the exit script returns to the shell. Using exit 0 is a good practice for quitting a simple script, indicating a successful run.
Note: If you exit using exit without parameters, the exit code will be the exit code for the last command in the script. Equivalent to exit $?.

Exec
Degree of importance: Medium
This shell built-in command will replace the current process with a specific command. Normally when the shell encounters a command, it will fork off a subprocess to actually run the command. With the exec built-in command, the shell will not fork, and the execution of the command will replace the current shell. So when we use it in the script, when the command is complete,
It will force the script to exit.

Ture
Degree of importance: high
A command that returns a successful (or return 0) exit code, but does nothing else.

Type[cmd]
Degree of importance: Medium
Similar to the which extension command, type cmd gives the full path of "cmd". Unlike the which command, the Type command is a Bash built-in command. A useful option is the-a option, which allows you to identify whether the identified parameter is a keyword or built-in command, or you can locate a system command with the same name.

Bind
Importance level: Low
Bind built-in commands are used to display or modify key bindings for readline[5].

Help
Degree of importance: Medium
Get a small summary of the use of shell built-in commands. This is more like the Whatis command, but help is built-in.

Job Control commands
Jobs
Degree of importance: Medium
Lists all running jobs in the background, giving the job number.

Disown
Degree of importance: Medium
From the current job table of the shell, delete the job.

FG, BG
Degree of importance: Medium
The FG command can put a job that runs in the background to the foreground to run. The BG command restarts a pending job and runs it in the background. If you do not specify a job number when using FG or BG commands, the default is to operate on the currently running job.

Wait
Degree of importance: Medium
Stop the script from running until all the jobs running in the background end, or until the job that specifies the job number or the process number is the option ends.
You can use the wait command to prevent the script from exiting before the background job finishes (which results in an orphan process).

Logout
Degree of importance: Medium
Exit a login shell, or you can specify an exit code.

Times
Degree of importance: Medium
Gives the time taken to execute the command, using the following form of output:
0m0.020s 0m0.020s
This is a very limited capability, so this is not often seen in shell scripts.

Kill
Degree of importance: high
Forces the end of a process by sending an appropriate end signal.

Command
Degree of importance: Medium
Command commands disable the lookup of aliases and functions. It only looks for internal commands and the scripts or executable programs found in the search path.

Take a look at the priority of Bash execution commands:
1. Aliases
2. Keywords
3. Functions
4. Built-in commands
5. Script or executable program ($PATH)

Builtin
Importance level: Low
Commands that are behind "builtin" will only invoke the built-in command. Temporarily disables a function with the same name or an extended command with the same name.

Enable
Importance level: Low
This command either disables the built-in command or restores the built-in command. For example: Enable-n kill will disable the kill built-in command, so when we call kill, we will use the/bin/kill external command.
The-a option restores the built-in commands, and all built-in commands are restored without parameters.
The option-f filename Loads a built-in command from the appropriate compiled target file [6] in the form of a shared library (DLL).

AutoLoad
Importance level: Low
This was transplanted from Ksh's autoloader command. A function with a "autoload" declaration that is loaded only when it is first called. Doing so 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 Enable command above).

Linux built-in commands

Related Article

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.