Get help with Linux shell built-in commands

Part of the Linux shell built-in commands belonging to the user, this article will tell you how to identify them and get help for using them.

Linux is built into the shell built-in commands in the command, like built-in wall shelves. The standard Linux commands stored in different ways in the / usr / bin in, you will not find them in a separate file, you may have used quite a lot of built-in commands, but you will not feel them with commands such as ls and pwd What is the difference .

As with other built-in commands using Linux commands, which may be greater than a similar command shell does not belong to the run a little faster. Bash built-in commands include alias, export and bg and so on.

As you feared, because the built-in commands are specific to the shell, so they do not offer manual page. Use man to see bg, you will see something like this:

  1. $ man bg
  2. No manual entry for bg

Another built-in command prompt judgment is that when you use the which command to identify the source of the command, Bash does not respond, indicates that the file is not associated with the built-in commands:

  1. $ which bg
  2. $

On the other hand, if your shell is / bin / zsh, you might get a response more enlightening:

  1. % which bg
  2. bg: shell built-in command

bash provides additional help, but it is achieved by using the help command:

  1. $ help bg
  2. bg: bg [job_spec ...]
  3. Move jobs to the background.
  4. Place the jobs identified by each JOB_SPEC in the background,asif they
  5. had been started with`&'. If JOB_SPEC is not present, the shell's notion
  6. of the current job is used.
  7. Exit Status:
  8. Returns success unless job control is not enabled or an error occurs.

If you want to view a list of all the built-in commands bash provides the use of compgen -b command. The command output through a pipe to the column in order to obtain a better list format.

  1. $ compgen -b | column
  2. . compgen exit let return typeset
  3. : complete exportlocalset ulimit
  4. [ compopt false logout shift umask
  5. aliascontinue fc mapfile shopt unalias
  6. bg declare fg popd source unset
  7. bind dirs getopts printf suspend wait
  8. break disown hash pushd test
  9. builtin echo help pwd times
  10. caller enable history read trap
  11. cdeval jobs readarray true
  12. command execkill readonly type

If you use the help command, you will see a list of built-in commands and a brief description. However, this list is truncated (with the help command at the end):

  1. $ help
  2. GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
  3. These shell commands are defined internally.Type`help' to see this list.
  4. Type `help name' to find out more about the function `name'.
  5. Use`info bash' to find out more about the shell in general.
  6. Use `man-k' or `info' to find out more about commands notinthislist.
  7. A star (*)next to a name means that the command is disabled.
  8. job_spec [&] history [-c][-d offset][n]or histo>
  9. (( expression ))if COMMANDS;then COMMANDS;[elif CO>
  10. . filename [arguments] jobs [-lnprs][jobspec ...]or jobs ->
  11. :kill[-s sigspec |-n signum |-sigsp>
  12. [Arg ...] Let arg [arg ...]
  13. [[ expression ]]local[option] name[=value]...
  14. alias[-p][name[=value]...] logout [n]
  15. bg [job_spec ...] mapfile [-d delim][-n count][-O ori>
  16. bind [-lpsvPSVX][-m keymap][-f filen> popd [-n][+N |-N]
  17. break[n]printf[-v var] format [arguments]
  18. builtin [shell-builtin [arg ...]] pushd [-n][+N |-N |dir]
  19. caller[expr]pwd[-LP]
  20. case WORD in[PATTERN [| PATTERN]...)> read [-ers][-a array][-d delim][-i>
  21. cd[-L|[-P [-e]][-@]][dir] readarray [-d delim][-n count][-O o>
  22. command [-pVv] command [arg ...] readonly [-aAf][name[=value]...]or>
  23. compgen [-abcdefgjksuv][-o option][->return[n]
  24. complete [-abcdefgjksuv][-pr][-DEI]> select NAME [in WORDS ...;]do COMMA>
  25. compopt [-o|+o option][-DEI][name ..>set[-abefhkmnptuvxBCHP][-o option-n>
  26. continue[n] shift [n]
  27. coproc [NAME] command [redirections] shopt [-pqsu][-o][optname ...]
  28. declare[-aAfFgilnrtux][-p][name[=va> source filename [arguments]
  29. dirs [-clpv][+N][-N] suspend [-f]
  30. disown [-h][-ar][jobspec ...| pid .<p&gt'> test [expr]
  31. echo [-neE] [arg ...] time [-p] pipeline
  32. enable [-a] [-dnps] [-f filename] [nam> times
  33. eval [arg ...] trap [-lp] [[arg] signal_spec ...]
  34. exec [-cl] [-a name] [command [argumen> true
  35. exit [n] type [-afptP] name [name ...]
  36. export [-fn] [name[=value] ...] or exp> typeset [-aAfFgilnrtux] [-p] name[=va>
  37. false ulimit [-SHabcdefiklmnpqrstuvxPT] [li>
  38. fc [-e ename] [-lnr] [first] [last] or> umask [-p] [-S] [mode]
  39. fg [job_spec] unalias [-a] name [name ...]
  40. for NAME [in WORDS ... ] ; do COMMANDS> unset [-f] [-v] [-n] [name ...]
  41. for (( exp1; exp2; exp3 )); do COMMAND> until COMMANDS; do COMMANDS; done
  42. function name { COMMANDS ; } or name (> variables - Names and meanings of som>
  43. getopts optstring name [arg] wait [-fn] [id ...]
  44. hash [-lr] [-p pathname] [-dt] [name .> while COMMANDS; do COMMANDS; done
  45. help [-dms] [pattern ...] { COMMANDS ; }

As can be seen from the list above, help command itself is built.

You can provide a built-in command name you are interested in to help command to get more information about them, such as help dirs:

  1. $ help dirs
  2. dirs: dirs [-clpv][+N][-N]
  3. Display directory stack.
  4. Display the list of currently remembered directories.Directories
  5. find their way onto the listwith the `pushd' command; you can get
  6. back up through the list with the `popd' command.
  7. Options:
  8. -c clear the directory stack by deleting all of the elements
  9. -l do not print tilde-prefixed versions of directories relative
  10. to your home directory
  11. -p print the directory stack with one entry per line
  12. -v print the directory stack with one entry per line prefixed
  13. with its position in the stack
  14. Arguments:
  15. +N Displays the Nth entry counting from the left of the list
  16. shown by dirs when invoked without options, starting with
  17. zero.
  18. -N Displays the Nth entry counting from the right of the list
  19. shown by dirs when invoked without options, starting with
  20. zero.
  21. Exit Status:
  22. Returns success unless an invalid option is supplied or an error occurs.

Built-in command provide most of the functionality of each shell. Any shell you're using has some built-in commands, but how to get these built-in command information may vary due to shell. For example, for zsh, you can use the command man zshbuiltins get its description of built-in commands.

  1. $ Man zshbuiltins
  2. ZSHBUILTINS(1)GeneralCommandsManual ZSHBUILTINS(1)
  3. NAME
  4. zshbuiltins - zsh built-in commands
  5. SHELL BUILTIN COMMANDS
  6. Some shell builtin commands take options as described in individual en‐
  7. tries; these are often referred to in the list below as`flags' to avoid
  8. confusion with shell options, which may also have an effect on the behav‐
  9. iour of builtin commands. In this introductory section, `option' always
  10. has the meaning of an option to a command that should be familiar to most
  11. command line users.

In this lengthy manual pages, you will find a list of built-in commands, which contains a useful description, as shown in the following excerpt:

  1. bg [ job ...]
  2. job ...&
  3. Put each specified job in the background,or the current job if
  4. none is specified.
  5. bindkey
  6. See the section `Zle Builtins' in zshzle(1).
  7. break [ n ]
  8. Exit from an enclosing for, while, until, select or repeat loop.
  9. If an arithmetic expression n is specified, then break n levels
  10. instead of just one.

At last

Linux built-in command is important for each shell, which is similar to that in the same shell-specific commands. If you often use a different shell, and notes that some of the commands you use often does not exist or can not seem to work as expected, then it is probably one of the other shell you are using the built-in command.

via:networkworld

Guess you like

Origin www.linuxidc.com/Linux/2019-07/159683.htm