The bash built-in command does not need to search the path provided in the environment variable $path, so it can be executed directly, so it is fast.
Here are a few simple, essential command usages.
1. Help
Purpose: Displays a list of all bash built-in commands, or the use of one of the built-in commands.
Usage:
4Help
Execution Result: Displays a list of all built-in commands.
4Help–s built-in commands
Execution Result: Displays the syntax format of the built-in command.
Case:
Help CD
Displays the detailed usage of the CD command.
Help–s printf
printf:printf [-v var] format [arguments]
Displays the syntax format of the printf command
2. Echo
Purpose: Used to display a line of text. The default is to wrap the lines automatically.
Usage:
4echo Hello World/echo "Hello world"/echo ' Hello World '
Execution Result: Displays the string Hello World.
4echo–n ' Hello world '
Execution Result: Display does not wrap.
4echo–e "I am the King \nof the world."
Option-E, which allows special characters in a string to be have, such as \ n, is interpreted as a newline character.
I am King
of the world.
3. printf
Purpose: Display parameter contents according to format
Syntax: printf "format string" parameter
A format character corresponds to the output of a parameter.
Suppose the variable str= "Hello World"
Usage:
4printf "%s\n" "$str" (%s string format)
Execution Result: The contents of the variable str are displayed, and \ n has a newline effect.
4 printf "%c\n" "$str" (%c character format)
Execution Result: Displays the first character h of the value of the STR variable.
4 printf "%s total%d characters \ n" "$str" one (%d integer format)
Execution result: Show Hello World in total of 11 characters.
4 printf "%f\n" (%f floating point format)
Execution result: Shows floating-point number 20.000000.
4 printf "%5s\n" Yes
Execution Result: Displays a 5-character-length string (right-aligned), and less than 5 characters are padded with whitespace.
4 printf "%-5s\n" Yes
Execution Result: Displays a 5-character string (left-aligned), and a portion less than 5 characters is padded with whitespace.
4 printf "%q\n" "$str"
Execution Result: Display hello\ world,%q will escape the special characters in the variable value with the \ character.
4 printf "%b" "abc\n123\nxyz\n"
Execution result:%b The escape character in the string (\ n, \ t, \v, \ ', \ \)
4.: (colon)
Purpose: Do nothing, return the true value (that is, pass back 0)
4 : >/path/to/file
Execution result: use: To create an empty file.
5.. (Half-width period)
Purpose: Executes the shell program in the current shell environment. Same as the source command
. /path/to/file
6. Alias
Purpose: Display, set program alias (aliases).
Usage:
4 alias
Execution result: Displays all current program aliases that have been set.
4 Alias New alias = ' combination of commands '
Execution result: Set a new alias for the program
Alias cp= ' Cp-f '
means that the CP is redefined with cp-f, and the execution of CP equals the execution of cp–f.
4 alias CP=CP
The CP alias is canceled, CP or the original CP.
7. Unalias
Purpose: Cancels the program alias.
Usage:
4 Unalias CP
Indicates that the alias setting of the CP is canceled.
8. Exit
Purpose: Leave the bash shell or harness script program.
Usage:
4 Exit 1
Indicates that you left the shell and returned a value of 1.
9. Logout
Purpose: Unregisters login Shell.
In the case where no strings are entered on the command line, if you press the "Ctrl+d" key combination, the function is equivalent to the logout instruction and can be logged off.
History
Purpose: Displays shell directives that have been executed in the past.
There are 3 variables related to history:
Histfile
4 Echo $HISTFILE
Execution Result:/root/.bash_history
A history script file that represents the root of the file, that is, the command that the root has executed is stored in this file.
Histfilesize
Specifies the number of rows for the history script file, and if the number of historical instructions exceeds the size of histfilesize, the order of the preceding instructions will be removed, but the sequence number of the respective history commands is unchanged.
Histsize
It is set in the shell of an interactive mode, with the number of historical instructions that can be remembered. Once the shell is finished, the history script file is only stored in the Histsize line number instruction.
One . FC
Purpose: Lists the commands that were recently executed after logging in to the host.
Usage:
4Fc–l
Read
Purpose: Reads a row of data from a standard input.
Usage: Read variable
Case:
Echo ' Please enter your English name? ‘
Read yname
Echo ' Your name is: '$yname
If you do not specify a variable to receive data after the read, the default variable name is reply
Echo ' Please enter your English name? ‘
Read
Echo ' Your name is: '$REPLY
The same can be achieved by using the READ–P approach:
Read–p ' Please enter your English name? ‘
Echo ' Your name is: '$REPLY
Option-P refers to the meaning of "hint message" followed by a string that prompts the user for input.
Read can fetch one row of data into an array at a time, using the following
Read-a Arr < < (Echo 123 45 97)
Option-A is to specify ARR as an array variable.
Extract array element value method:
echo ${arr[n]} N starting from 0
Shopt.
Purpose: Displays and sets the shell's behavior options to enhance the shell's ease of use.
Usage: shopt
Case:
4 shopt–p or Shopt
Execution result: Show all shell action options that can be set
4 shopt–s Mailwarn
Execution result: Enable message alert option
4 shopt–u Mailwarn
Execution result: Turn off message alert option
This article is from the "Craft Life" blog, so be sure to keep this source http://allenh.blog.51cto.com/481430/1695339
Linux Basics: Bash Shell built-in commands