コマンドの存在確認の可否を比較する
使用するコマンド
which
type
command -v
hash
存在を確認する対象
cd (組み込みコマンド)
ls (外部コマンド)
if (予約語)
ll (エイリアス: alias ll="ls -l")
fn (関数: fn(){ :; })
zsh
| command |
cd |
ls |
if |
ll |
fn |
which |
○ |
○ |
○ |
○ |
○ |
type |
○ |
○ |
○ |
○ |
○ |
command -v |
○ |
○ |
○ |
○ |
○ |
hash -m |
○ |
○*1 |
× |
× |
× |
ls を一度実行し、ハッシュ表に乗った後に限る。
bash
| command |
cd |
ls |
if |
ll |
fn |
which |
○*1 |
○ |
× |
× |
× |
type |
○ |
○ |
○ |
○ |
○ |
command -v |
○ |
○ |
○ |
○ |
○ |
hash -t |
× |
○*2 |
× |
× |
× |
which cd はPATH上の cd の実体を指すため組み込み cd の存在確認は行えない。
ls を一度実行し、ハッシュ表に乗った後に限る。
ksh
| command |
cd |
ls |
if |
ll |
fn |
which |
○*1 |
○ |
× |
× |
× |
type |
○ |
○ |
○ |
○ |
○ |
command -v |
○ |
○ |
○ |
○ |
○ |
hash |
×*2 |
×*2 |
×*2 |
×*2 |
×*2 |
which cd はPATH上の cd の実体を指すため組み込み cd の存在確認は行えない。
hash は常に成功するため存在確認は行えない。
tcsh
| command |
cd |
ls |
if |
ll |
fn |
which |
○ |
○ |
○ |
× |
× |
type |
○ |
○ |
○ |
× |
× |
command -v |
○ |
○ |
○ |
× |
× |
hash |
× |
× |
× |
× |
× |
csh
| command |
cd |
ls |
if |
ll |
fn |
which |
○ |
○ |
○ |
× |
× |
type |
○ |
○ |
○ |
× |
× |
command -v |
○ |
○ |
○ |
× |
× |
hash |
× |
× |
× |
× |
× |