最近私はコマンドを見つけました:command 手動入力はありませんが、ヘルプは次のように表示されます:
$ help command
command: command [-pVv] command [arg ...]
Execute a simple command or display information about commands.
Runs COMMAND with ARGS suppressing shell function lookup, or display
information about the specified COMMANDs. Can be used to invoke commands
on disk when a function with the same name exists.
Options:
-p use a default value for PATH that is guaranteed to find all of
the standard utilities
-v print a description of COMMAND similar to the `type' builtin
-V print a more verbose description of each COMMAND
Exit Status:
Returns exit status of COMMAND, or failure if COMMAND is not found.
command -vです whichの代替です ?
このコマンドで受け入れられる引数とcommandの使用方法/タイミング ?
ベストアンサー
command バッシュビルトインです ご覧のとおり:
[email protected]:~$ type command
command is a shell builtin
つまり、command 私たちのシェル、bashによって提供されます。 man bashを掘り下げる その用途を確認できます:
(man bashから ):
command [-pVv] command [arg ...]
Run command with args suppressing the normal shell function
lookup. Only builtin commands or commands found in the PATH are
executed. If the -p option is given, the search for command is
performed using a default value for PATH that is guaranteed to
find all of the standard utilities. If either the -V or -v
option is supplied, a description of command is printed. The -v
option causes a single word indicating the command or file name
used to invoke command to be displayed; the -V option produces a
more verbose description. If the -V or -v option is supplied,
the exit status is 0 if command was found, and 1 if not. If
neither option is supplied and an error occurred or command
cannot be found, the exit status is 127. Otherwise, the exit
status of the command builtin is the exit status of command.
基本的に、commandを使用します 「通常の関数ルックアップ」をバイパスします。たとえば、.bashrcに関数があるとします。 :
function say_hello() {
echo 'Hello!'
}
通常、say_helloを実行すると ターミナルでbashはsay_helloという名前の関数を見つけます .bashrcで 前 たとえば、say_helloという名前のアプリケーションが見つかりました 。使用:
command say_hello
bashが通常の関数ルックアップをバイパスし、ビルトインまたは$PATHのいずれかに直接移動するようにします 。この関数ルックアップもであることに注意してください エイリアスを含めます。 commandの使用 関数とエイリアスの両方をバイパスします。
-pの場合 オプションが提供されていますbashはカスタムの$PATHをバイパスします 独自のデフォルトを使用します。
-v または-V flags bashは説明を出力します(-vの略) 、-Vの長い )コマンドの。
注:souravcがコメントで指摘しているように、シェルビルトインに関する情報を見つけるためのより簡単な方法はここにあります:シェルビルトインのコマンドとキーワードに対して `man`を機能させる方法は?