Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

I have seen both in Cygwin and in Linux the [ command under /bin. Whenever I run it I get an error saying: missing ].

I never understood what this command does, I just one day found it wanted to find out what it does (and whether it is useful or not)

NOTE: I would have checked the man entry, for an answer, but sadly, there is no entry in it for [

share|improve this question

marked as duplicate by JdeBP, Tog, Kevin Panko, Shakehar, Mark Mar 17 at 19:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
What is the command? –  QMechanic73 Mar 14 at 23:18
1  
@TiagoƇ. The command is called [ –  inixsoftware Mar 14 at 23:18
    
In bash, it is re-implemented as a built-in command. At a bash prompt type help [ –  glenn jackman Mar 15 at 0:13
add comment

3 Answers 3

up vote 6 down vote accepted

This is test command.

For example, find out if /etc/passwd exists or not:

[ -f /etc/passwd ] && echo "Yes" || echo "No"

Regularly you write it as follows:

if test -f /etc/passwd
then
  echo "Yes"
else
  echo "No"
fi
Read 
share|improve this answer
add comment

Have you ever seen/noticed if conditions in shell scripts? They are of the form:
[ -e $FILE ]

In those cases, the condition checking functionality is usually built-into the shell interpreting those scripts, usually bash or sh-aliased-bash.

The binaries that you see serve the same purpose, but are present so condition checks can be used in shells without such functionality built-in.

share|improve this answer
add comment

The [ square bracket is another way to call the test command.

Refer to test's Man page for further info :)

share|improve this answer
add comment

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