What is /usr/bin/[?
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/[
:)
Related videos on Youtube
user1652922
Updated on September 17, 2022Comments
-
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 about 14 yearsBut unlike test it requires the last arg to be a ]
-
Josh about 14 yearsThanks. That's what I figured but I was surprised because I thought [ was a bash builtin
-
Josh about 14 yearsI would accept your answer but Zypher beat you to it by a few seconds... sorry :-)
-
Mo. about 14 years
[
is a bash builtin, but so istest
. not all shells are created equal — in plenty of them,test
(and[
) aren’t builtins. -
Matt Simmons about 14 yearsThere 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 about 14 yearstest 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 about 14 yearsOr try
type -a [
which will show that[
is a Bash builtin and/usr/bin/[
. The order shown is the order of preference. -
Josh about 14 yearsThis must be the most upvoted string of comments ever, lol.
-
user1686 about 14 years
[ $VAR ]
fails when$VAR
is empty or not set. Use[ "$VAR" ]
instead.