Could someone tell me if there is any difference in using square brackets single or doubled pair?
So, do those two some how could be treted by shell differently:
if [ <condition> ] ; then <statements;> else <statements;> fi
and
if [[ <condition> ]] ; then <statements;> else <statements;> fi
Maybe any one could provide with any additional shell usage compare to another?
Thank you,
Alex
If you use "[.....]" you are actually using /bin/test (/bin/[). Try man [ and you will get the test(1) manpage.
If you use [[.....]] you are using bash's builtin test . Using a builtin is faster and more efficient since no fork/exec is required.
These days they are both built-ins:
$ echo $BASH_VERSION
3.2.39(19)-release
$ type [
[ is a shell builtin
$ type [[
[[ is a shell keyword
$
[ is included mostly for backward compatibility to Bourne shell and the /usr/bin/test that fpmurphy mentioned. I usually prefer the syntax of [[.
Thank you, guys for reply!
So, from user point of view there is no difference in usage [ ... ] or [[ ... ]]?
Is it correct?
Having by today both as a part of shell (buildin and keyword) now it is really hard to say witch one could be more efficient, right?
For portability use [.....] . For efficiency, use [[.....]]