Tools built into the shell
Is there any way to find out what stuff are built in?
help
will get you a complete list. You can run help
with a builtin command as argument to get more detailed information. info "(bash) Shell Builtin Commands"
will display the Bash manual for all the builtins.
Is the
pwd
in thebin
folder (above) the samepwd
that is built in?
No, they are completely different:
$ builtin pwd --helpbash: pwd: --: invalid optionpwd: usage: pwd [-LP]$ /bin/pwd --helpUsage: /bin/pwd [OPTION]...Print the full filename of the current working directory. -L, --logical use PWD from environment, even if it contains symlinks -P, --physical avoid all symlinks --help display this help and exit --version output version information and exitNOTE: your shell may have its own version of pwd, which usually supersedesthe version described here. Please refer to your shell's documentationfor details about the options it supports.Report bugs to <bug-coreutils@gnu.org>.
Why are stuff built in in the first place? Are they especially tweaked to fit the shell, or is it just so that they can be invoked internally so they don't require a new process?
From the manual: "Builtin commands are necessary to implement functionality impossible or inconvenient to obtain with separate utilities." It would be hard to make a command like cd
work externally because it affects the state of the shell. Of course, it is easy to duplicate the behavior of pwd
or true
, but the POSIX standard requires that they are built-ins.
I managed to catch a
pwd
withpwd &
andps
. Is this a circumvention or are they separate processes?
Running builtin &
will cause Bash to run a subshell in the background. You can see this easily by doing read &
, since read
waits until it has input.
To answer your first question, I found that if I type (in my bash shell) "builtin" and then tab-tab, it shows me a list of the builtins, since it has tab-completion. I know it's only a small part of what you're asking, but it's a start, since I don't know all the "why" stuff. :P
Shell builtins are obviously more efficient than separate binaries. The separate binaries are totally independent and are basically for use with other shells that do not have this stuff builtin. You can force bash to use binary by putting the command in quotes, IIRC. If you man bash
you will find quite some information on builtin commands and how exactly they work (it's not always the same like external binaries).