我想知道 bash
shell 中内置的工具。例如,type pwd
告诉我 pwd
内置在 shell 中。
whereis pwd
/bin/pwd /usr/include/pwd.h /usr/share/man/man1/pwd.1.gz
aptitude search pwd
没有(似乎)在我使用的密码上提供任何信息。 (我在 Debian 系统上。)
-- 有什么方法可以找出内置的东西吗?除了用 type
进行暴力破解,就是这样。
-- bin
文件夹(上)中的pwd
是否与内置的pwd
相同?它是否在启动时加载到 shell 中?或者它是由 shell 从该文件夹执行的吗?如果是这样,它是通过什么方式内置的?
-- 为什么首先要内置这些东西?它们是经过特别调整以适应 shell ,还是只是为了可以在内部调用它们而不需要新进程?我设法用 pwd &
和 ps
捕获了一个 pwd
。这是规避还是它们是单独的过程?
-- 请随时告诉我关于该主题的任何其他信息 :)
最佳答案
Is there any way to find out what stuff are built in?
help
将为您提供完整列表。您可以使用内置命令作为参数运行 help
以获得更多详细信息。 info "(bash) Shell Builtin Commands"
将显示所有内置命令的 Bash 手册。
Is the
pwd
in thebin
folder (above) the samepwd
that is built in?
不,它们完全不同:
$ 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 <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?
来自手册:“内置命令对于实现使用单独的实用程序不可能或不方便获得的功能是必要的。”很难让像 cd
这样的命令在外部工作,因为它会影响 shell 的状态。当然,复制 pwd
或 true
的行为很容易,但是 POSIX 标准 requires that they are built-ins .
I managed to catch a
pwd
withpwd &
andps
. Is this a circumvention or are they separate processes?
运行 builtin &
将导致 Bash 在后台运行一个子 shell。您可以通过执行 read &
轻松地看到这一点,因为 read
会等待输入。
关于bash - shell 内置工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8481018/