ksh if block question

Hi,

I am looking at a script, and it contains lines like:

if [[ $(echo $* | egrep -c 'DG') -eq 0 ]]
...

This is getting me confused. Why do we need $ before (echo $* | egrep -c 'DG')? Why can't we simply have:

if [[ (echo $* | egrep -c 'DG') -eq 0 ]]
...

i.e. no $ here before the ()...

Thanks.

J

Hi.

Do you get the same result when you omit the "$"? ... cheers, drl

Because the shell won't do command execution within the if condition, it will error out:

                           conditional binary operator expected

The condition expects an integer within itself, that's why you need the command substitution structure $( ) , where now the shell is told to execute the command within the braces:

or similarly:

Excellent. Now it is clear.

Thanks.