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 🙂
helpwill get you a complete list. You can runhelpwith a builtin command as argument to get more detailed information.info "(bash) Shell Builtin Commands"will display the Bash manual for all the builtins.No, they are completely different:
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
cdwork externally because it affects the state of the shell. Of course, it is easy to duplicate the behavior ofpwdortrue, but the POSIX standard requires that they are built-ins.Running builtin
&will cause Bash to run a subshell in the background. You can see this easily by doingread &, sincereadwaits until it has input.