f



Bash operator performance: test [...] vs. extended test [[...]]

Hello,

I can't seem to find any difference in performance between the regular [...]
and extended test [[...]] operators in Bash.

If I want to increase performance in a situation which does not require the
globbing features of the extended test operator, should I just use the
normal test operator instead?

Thanks.
0
foo
7/26/2004 7:12:39 AM
comp.unix.shell 15484 articles. 3 followers. Post Follow

3 Replies
542 Views

Similar Articles

[PageSpeed] 11

2004-07-26, 07:12(+00), foo:
> I can't seem to find any difference in performance between the regular [...]
> and extended test [[...]] operators in Bash.

The difference is more on the syntax. "[" is a shell builtin
command, parsed as any other command, and then an internal
function does the handling.

[[ ... ]] is a shell separate construct, parsed specially as a
test expression, not a command.

In the end, I guess the same internal function is used to
perform the actual testing.

> If I want to increase performance in a situation which does not require the
> globbing features of the extended test operator, should I just use the
> normal test operator instead?
[...]

The difference lays in relative performance of both parsers. If
you're concern with efficiency, don't use shells in the first
place (especially not bash).

-- 
Stephane
0
Stephane
7/26/2004 7:21:29 AM
foo <foo@bar.baz> wrote in message news:<H92Nc.187618$XM6.70136@attbi_s53>...
> Hello,
> 
> I can't seem to find any difference in performance between the regular [...]
> and extended test [[...]] operators in Bash.
> 
> If I want to increase performance in a situation which does not require the
> globbing features of the extended test operator, should I just use the
> normal test operator instead?
> 
> Thanks.

Some of the functional differences include:

 - [[ ]] more test operators supported
 - [[ ]] supports pattern matching ( [ ] does not )


--------------------------------------------------------
Dana French                            dfrench@mtxia.com
Mt Xia Technical Consulting Group   http://www.mtxia.com
100% Spam Free Email              http://www.ridmail.com
MicroEmacs                      http://uemacs.tripod.com
Korn Shell Web     http://dfrench.tripod.com/kshweb.html
0
dfrench
7/26/2004 2:36:44 PM
2004-07-26, 07:36(-07), Dana French:
[...]
> Some of the functional differences include:
>
>  - [[ ]] more test operators supported
>  - [[ ]] supports pattern matching ( [ ] does not )
[...]

It also doesn't suffer from the design errors as [ ones.

(where operators can be taken as operands)

-- 
Stephane
0
Stephane
7/27/2004 4:15:45 PM
Reply: