2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

シェルスクリプト type コマンド

Posted at

type コマンドでは、指定されたコマンドが、外部コマンドなのか、組み込みコマンドなのか、シェル関数なのかを調べることが可能。
普段、自分がよく使うコマンドに対して、type コマンドで調べてみると新しい発見があるかもしれない。

type-example1.sh
# ls は外部コマンドで、エイリアスが設定されている
$ type ls
ls is aliased to `ls --color=auto'

# ll は ls でエイリアスが設定された外部コマンド
$ type ll
ll is aliased to `ls -alF'

# cd は 組み込みコマンド
$ type cd
cd is a shell builtin

# cp は外部コマンド /bin/cp に存在する
$ type cp
cp is hashed (/bin/cp)

# function はシェルにおけるキーワードの一つ
$ type function
function is a shell keyword

# func というコマンドは存在していない
$ type func
bash: type: func: not found

# func シェル関数を定義
$ func(){ echo "ABC"; }

# 今度は定義したシェル関数が表示される
$ type func
func is a function
func () 
{ 
    echo "ABC"
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?