Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the if [ -e $name ], what condition check is -e?
$name is a variable of a path to a directory.

share|improve this question
up vote 6 down vote accepted

-e returns true if the target exists. Doesn't matter if it's a file, pipe, special device, whatever. The only condition where something may exist, and -e will return false is in the case of a broken symlink.

For example:

$ ln -s foo bar

$ [ -e foo ]; echo $?

$ touch bar

$ [ -e foo ]; echo $?

In bash you can do help test to see what test options you have.

[ is usually part of your shell. In bash the options and behaviors are defined by bash. It is also kind of a synonym for test. In bash you can do help test to see all the options it supports.
The only real difference between [ and test should be that [ requires a ] after your arguments, whereas test does not. They otherwise work the same, [ -e foo ] is equivalent to test -e foo.

There is also /usr/bin/[ for shells which do not have [ built in. There is no man page for this though. But there is also a /usr/bin/test, and my system does have a man test which covers the options. I haven't tested, but I'd bet all the options supported by /usr/bin/test work on /usr/bin/[.

share|improve this answer
[ and test are indeed the same program (and the POSIX spec requires them to be). Someone in the dim recesses of time thought that providing a synonym for test--right down to the required but unused ] argument--was a good idea, but it's just been a source of confusion for countless beginners who think the [ and ] really are shell syntax. – chepner May 6 '14 at 15:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.