どのようなものが組み込まれているかを調べる方法はありますか?
help
完全なリストが表示されます。組み込みコマンドを引数として実行するhelp
と、より詳細な情報を取得できます。info "(bash) Shell Builtin Commands"
すべてのビルトインの Bash マニュアルが表示されます。
フォルダー内 (上記) は、組み込まpwd
れているものと同じですか?bin
pwd
いいえ、それらは完全に異なります。
$ 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>.
そもそもなぜ物が組み込まれているのですか?それらはシェルに合うように特別に調整されていますか、それとも新しいプロセスを必要としないように内部で呼び出せるようにするためですか?
マニュアルから: 「別のユーティリティでは取得できない、または不便な機能を実装するには、組み込みコマンドが必要です。」cd
シェルの状態に影響を与えるため、コマンドのようなコマンドを外部で機能させるのは難しいでしょう。もちろん、pwd
またはの動作を簡単に複製できますtrue
が、POSIX 標準では、それらが組み込みの である必要があります。
とで apwd
をキャッチすることができました。これは回避策ですか、それとも別のプロセスですか?pwd &
ps
builtin を実行&
すると、Bash はバックグラウンドでサブシェルを実行します。は入力があるまで待機するためread &
、 を実行することでこれを簡単に確認できます。read