Checking in bash and csh if a command is builtin

Natan Yellin picture Natan Yellin · Sep 13, 2011 · Viewed 7k times · Source

How can I check in bash and csh if commands are builtin? Is there a method compatible with most shells?

Answer

Jon Lin picture Jon Lin · Sep 13, 2011

You can try using which in csh or type in bash. If something is a built-in command, it will say so; otherwise, you get the location of the command in your PATH.

In csh:

# which echo
echo: shell built-in command.

# which parted
/sbin/parted

In bash:

# type echo
echo is a shell builtin

# type parted
parted is /sbin/parted

type might also show something like this:

# type clear
clear is hashed (/usr/bin/clear)

...which means that it's not a built-in, but that bash has stored its location in a hashtable to speed up access to it; (a little bit) more in this post on Unix & Linux.