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
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.