What is /usr/bin/[?

116

Solution 1

It's an alternative form of the 'test' command. Mostly used in scripts.

i.e.

if [ $VAR ]
then
    echo $VAR exists!
fi

Solution 2

It's what you call when you are using something like

if [ -e foo ]; then ...

in a shell script (but most shells have it as a buildin this days). man test should give you the docs.

Solution 3

As others pointed out, [ is the shell's condition evaluation utility - test.

In fact, there is a manual page for that!

$ man [

should give you more details about the opening square bracket.

Btw, in OS X, [ is located in /bin/[ :)

Share:
116

Related videos on Youtube

user1652922
Author by

user1652922

Updated on September 17, 2022

Comments

  • user1652922
    user1652922 almost 2 years

    I have a list view populate with numbers, and a edit text that sum the amount of numbers in the list view, I have written a implementation of ontouch, to delete rows in the list view, my question is: is there a way to delete the value that I delete in the list view on the edit text. for example if I delete the row 7 of 10 rows and its has a value of 5, and the amount is 35 display on the edit text, now the edit text must have 30.

    thank you I will appreciate it

    here some codes:

     private void showListViewData() {
    
        String z = "";
        String zQN = "Nu";
        String zPL = "Pl";  
        String zTR = "Tr";
    
        int x = Integer.parseInt(inJugada.getText().toString());
        int y = Integer.parseInt(inValor.getText().toString());
    
        String s = Integer.toString(x); 
    
        inJugada.setText(s);
    
        inValor.setText(String.valueOf(y));
    
       if(s.length() == 2){
           z = zQN;
    
       }else if(s.length() == 4){
    
           z = zPL;
    
       }else if(s.length() == 6){
           z = zTR;
       }
    
        for(int i=0; i<mData.size(); i++)
            mData.get(i);
    
        mData.add(new Data(z, x, y));
        Collections.sort(mData);
        Collections.synchronizedCollection(mData);
    
        // add new data to list and refresh
        mAdapter.notifyDataSetChanged();
    
  • Florian Diesch
    Florian Diesch about 14 years
    But unlike test it requires the last arg to be a ]
  • Josh
    Josh about 14 years
    Thanks. That's what I figured but I was surprised because I thought [ was a bash builtin
  • Josh
    Josh about 14 years
    I would accept your answer but Zypher beat you to it by a few seconds... sorry :-)
  • Mo.
    Mo. about 14 years
    [ is a bash builtin, but so is test. not all shells are created equal — in plenty of them, test (and [) aren’t builtins.
  • Matt Simmons
    Matt Simmons about 14 years
    There is a bash built-in, or at least, my system is acting as though there is. [ --help gives different input than /usr/bin/[ --help
  • Zoredache
    Zoredache about 14 years
    test and [ are builtin to bash, but not necessarily all other shells. You could temporarily move out of the path and run a bash script that uses either and you will see that the script still works.
  • Dennis Williamson
    Dennis Williamson about 14 years
    Or try type -a [ which will show that [ is a Bash builtin and /usr/bin/[. The order shown is the order of preference.
  • Josh
    Josh about 14 years
    This must be the most upvoted string of comments ever, lol.
  • user1686
    user1686 about 14 years
    [ $VAR ] fails when $VAR is empty or not set. Use [ "$VAR" ] instead.