Passion/bash

명령어 찾기(type, command, which)

sunshout 2013. 4. 25. 10:42

o  명령어 찾기(type vs. command, which)

쉘 프로그래밍을 하다보면 다른 명령어를 실행해야 하는데 해당 명령어가 존재하는지를 파악할 필요가 있다. 이 때 사용하는 명령어가 type 또는 command, which 이다.

 

type bash 스크립트에서 사용할 수 있는 built-in 기능이며, 좀더 compatibility를 가지려면 command -v <명령어>를 수행하는 것이 좋다.

 

root@cnode01:~# type vi

vi is hashed (/usr/bin/vi)

root@cnode01:~# command -v vi

/usr/bin/vi

root@cnode01:~# which vi

/usr/bin/vi