Hello,
I am having a problem when i execute following script on RHEL 6.4. Same script works fine on another machine where I have same version of RHEL and KSH.
Below is the rpm and RHEL version.
ossvm12(0)> rpm -qa | grep ksh
ksh-20100621-19.el6.x86_64
[/root]
ossvm12(0)> cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
With same RHEL and rpm version the script works fine on another machine.
I am trying to figure out what can effect this simple check "-ge" in ksh.
#!/bin/ksh
i=10
j=10.1
if [ $i -ge $j ]
then
echo "$i ge $j"
fi
In above script i have hard coded i and j for demo purpose. I have given -x option to get the debug info. Below is how i get it it.
[root@snmp1 ~]# /tmp/t.ksh
+ i=10
+ j=10.01
+ [ 10 -ge 10.01 ]
/tmp/t.ksh[5]: [: 10.01: arithmetic syntax error
[root@snmp1 ~]
I know "[" will invoke "test" command. But when i have same version fo KSH and RHEL on 2 machines, why does above script have different results ?
Somehow the "-ge" option is not working.
I even verified checksum of /bin/ksh93 which gets shipped in rpm on these 2 machines. Both are same.
What could be the cause ? Any more information needed ? Please help.
there's no 'floating number' arithmetic in ksh AFAIK.
Try:-
if [ $(($i)) -ge $(($j)) ]
.....
---------- Post updated at 06:24 PM ---------- Previous update was at 06:21 PM ----------
'ksh' can do floating point arithmetic at least on 1993 versions...
Yes KSH supports floating point arithmetic. I am not getting why its behaving weirdly in 1 machine when it works on the other. What can cause this sort of problem is what I am looking for.
Thanks,
Adithya
The most likely cause is that you're using a 1993 version of ksh
on the system where it works, but using a 1988 version of ksh
or some non- ksh
shell on the other system.
What is the output from the commands:
type ksh
echo $SHELL
ksh --version
/bin/ksh --version
on the system where your code works.
What is the output from those same commands on the system where it doesn't work?
Hello,
Thanks all for your time. Actually the problem was with the LC_ALL configuration. On the machine where there was arithmetic syntax error it was "fr_FR.UTF-8".
If I set the LC_ALL to "fr_FR.UTF-8" as shown below I can reproduce the problem.
root(0)> LC_ALL=fr_FR.UTF-8
[/root]
root(0)> locale
LANG=fr_FR.UTF-8
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=fr_FR.UTF-8
[/root]
root(0)> cat /tmp/t.ksh
#!/bin/ksh
i=10
j=10.01
if [ $i -ge $j ]
then
echo "$i is ge $j"
else
echo "$j is ge $i"
fi
[/root]
root(0)> /tmp/t.ksh
/tmp/t.ksh[6]: [: 10.01: arithmetic syntax error
10.01 is ge 10
To solve the problem, set LC_ALL=C.
root(0)> LC_ALL=C
[/root]
root(0)> /tmp/t.ksh
10.01 is ge 10
[/root]
Thanks,
Adithya
2 Likes
It really wants 10,01 (comma). How awful is that?
At least, in RedHat 5 I get consequently
LC_CTYPE="fr_FR.UTF-8"
ksh: [: 10.01: erreur arithmétique de syntaxe
LC_CTYPE="de_DE@euro"
ksh: [: 10.01: arithmetischer Syntaxfehler