if test for higher value between 2 decimal numbers

Hi
I would like to test for a max number value. It may be a decimal so I know I have to pipe into bc.
I just cannot get the syntax for this to work. I cannot get passed an error with the bracket - see below.
Any help appreciated.
Regards
Ewan

This works:

[ewan@sbc-san-01]/export/home/ewan> cat xx.ksh
#!/bin/sh
uname -a

max=6
val=3
if [ $max -gt $val ]
  then
    echo MAX $max VAL $val
  fi

Output:

[ewan@sbc-san-01]/export/home/ewan> ./xx.ksh   
SunOS sbc-san-01 5.10 Generic_144488-12 sun4v sparc SUNW,SPARC-Enterprise-T5220
MAX 6 VAL 3

This fails:

[ewan@sbc-san-01]/export/home/ewan> cat ./xx.ksh
#!/bin/sh
uname -a

max=6
val=3
#if [ $max -gt $val ]
if [ $(echo "$max -gt $val" |bc) -eq 1 ]
  then
    echo MAX $max VAL $val
  fi

Output:

[ewan@sbc-san-01]/export/home/ewan> ./xx.ksh    
SunOS sbc-san-01 5.10 Generic_144488-12 sun4v sparc SUNW,SPARC-Enterprise-T5220
./xx.ksh: syntax error at line 7: `(' unexpected
% max=3.11111; val=3.11101

% if [ $(echo "$max > $val" |bc) -eq 1 ]
then
echo MAX $max VAL $val
fi
MAX 3.11111 VAL 3.11101

And this is what I get:

[ewan@sbc-san-01]/export/home/ewan> cat ./xx.ksh
#!/bin/sh
uname -a

max=6.3
val=3.2
#if [ $max -gt $val ]
if [ $(echo "$max < $val" |bc) -eq 1 ]
  then
    echo MAX $max VAL $val
  fi


[ewan@sbc-san-01]/export/home/ewan> ./xx.ksh    
SunOS sbc-san-01 5.10 Generic_144488-12 sun4v sparc SUNW,SPARC-Enterprise-T5220
./xx.ksh: syntax error at line 7: `(' unexpected

What shell did you use, Yazu?

You have the shells mixed up. As far as I remember, /bin/sh is the original bourne shell on Solaris, which has less features than the Korn shell (ksh), including the $() function.

zsh But $(...) is POSIX.
I'm sure pludi is right. You can use `echo ...` instead of $(...) in the original Bourne shell.

I've tried ksh and sh below.
Ewan

#!/bin/ksh
uname -a

max=6.3
val=3.2
#if [ $max -gt $val ]
if [ `echo "$max < $val" |bc` -eq 1 ]
  then
    echo MAX $max VAL $val
  fi

output:
[ewan@sbc-san-01]/export/home/ewan> ./xx.ksh
SunOS sbc-san-01 5.10 Generic_144488-12 sun4v sparc SUNW,SPARC-Enterprise-T5220
syntax error on line 1, teletype
./xx.ksh[7]: test: argument expected

#!/bin/sh
uname -a

max=6.3
val=3.2
#if [ $max -gt $val ]
if [ `echo "$max < $val" |bc` -eq 1 ]
  then
    echo MAX $max VAL $val
  fi

output:
[ewan@sbc-san-01]/export/home/ewan> ./xx.sh
SunOS sbc-san-01 5.10 Generic_144488-12 sun4v sparc SUNW,SPARC-Enterprise-T5220
syntax error on line 1, teletype
./xx.sh: test: argument expected