I was wondering about tools that are built into the bash shell. For example, type pwd tells me that pwd is built into the shell.
whereis pwd
/bin/pwd /usr/include/pwd.h /usr/share/man/man1/pwd.1.gz
aptitude search pwd
does not (seem to) give anything on the pwd I use. (I'm on a Debian system.)
-- Is there any way to find out what stuff are built in? Besides brute force with type, that is.
-- Is the pwd in the bin folder (above) the same pwd that is built in? Is it loaded into the shell at initiation? Or is it executed from that folder by the shell? If so, in what way is it built-in?
-- 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? I managed to catch a pwd with pwd & and ps. Is this a circumvention or are they separate processes?
-- Feel free to tell me anything else on the topic :)
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
pwdin thebinfolder (above) the samepwdthat is built in?
No, they are completely different:
$ builtin pwd --help
bash: pwd: --: invalid option
pwd: usage: pwd [-LP]
$ /bin/pwd --help
Usage: /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 exit
NOTE: your shell may have its own version of pwd, which usually supersedes
the version described here. Please refer to your shell's documentation
for details about the options it supports.
Report bugs to <[email protected]>.
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
pwdwithpwd &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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With