Where is the read command?

read is a shell builtin, not an external command. which only tells you about external commands. Assuming you're using Bash (or some other Bourne-style shell), you should typically use type or command -v instead of which.

ek@Cord:~$ type read
read is a shell builtin

type and command are themselves shell builtins and they know not just about external commands but also about keywords, builtins, aliases, and functions. which is an external command that doesn't know about those things; it only knows about external commands. Sometimes which doesn't turn up anything when you ask it about a command that you can use in your shell. Sometimes it does turn up something for a command, but it isn't the same thing that actually runs when you use the command in your shell.

ek@Cord:~$ type type command which
type is a shell builtin
command is a shell builtin
which is /usr/bin/which

In Bash, you can see all the current possible meanings for a command, in the order that they are tried, with type -a:

ek@Cord:~$ type -a read
read is a shell builtin
ek@Cord:~$ type -a echo
echo is a shell builtin
echo is /bin/echo

For more information about why you usually shouldn't use which, and what to use instead in various shells including Bash, see Why not use “which”? What to use then?

Tags:

Command Line