What is /bin/[ ?

Discussion in 'macOS' started by Toe, Dec 7, 2006.

  1. Toe macrumors 65816

    Toe

    Joined:
    Mar 25, 2002
    #1
    Sorry if this is a unix noob question, but... no that's not a typo.

    In your Terminal, do:
    ls -la /bin

    That will show you a directory of everything in your root bin directory (bin is for "binaries," roughly the unix word for applications). In there, the first file (on two of my Tiger computers, anyway) is called: [

    What the heck is that?

    TIA
     
  2. kalisphoenix macrumors 65816

    kalisphoenix

    Joined:
    Jul 26, 2005
  3. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #3
    [ is an alias of the test command.

    It lets you use shorter syntax in a shell script.

    Type "man test" for all of the gory details about that command.

    Example: Normal syntax:
    Code:
    if test -f $1
    then
        echo File $1 exists.
    else
        echo File $1 does not exist.
        fi
    Shortcut syntax, using [ and also using ; instead of a linebreak:
    Code:
    if [ -f $1 ] ; then
        echo File $1 exists.
    else
        echo File $1 does not exist.
        fi
     

Share This Page