11

Enter image description here

See the screen shot.

There is the '[' file at /bin.

What is the '[' file? What does it do?

1 Answer 1

12

This command is for comparing values, checking file types etc.

Here's a man page:

NAME
 test, [ -- condition evaluation utility

SYNOPSIS
 test expression
 [ expression ]

It's usually used like this:

if [ -f /etc/passwd ] 
then
   echo "Yes"
else
   echo "No"  
fi

For more info, please read the man page ( man [ ).

3
  • 6
    It's worth noting that the default shell likely has its own builtin version of the [ command that will run instead of the one in /bin. The one in /bin is likely only for compatibility and for particularly minimalist shells.
    – Muzer
    Commented Dec 29, 2016 at 11:32
  • Actually, the command, [ on the filesystem, exists for POSIX compliance (IEEE Std 1003.2 (``POSIX.2'')) and not for compatibility or particularly minimalist shells. Commented Feb 19, 2019 at 12:45
  • omg I thought my cat had haxored my mac and renamed a core system file to [. but this is used in the if command! amaze! Ingenious.
    – Tomachi
    Commented Jan 22, 2021 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .