ksh Arithmetic syntax error while comparing decimal numbers
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.
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.
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.
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.
Last edited by Adithya Gokhale; 08-13-2015 at 02:32 PM..
Reason: code tags, pls
KSH-93 allows you to do integer arithmetic in any base from two to sixty-four. You can also do double precision floating point arithmetic. Almost the complete set of C language operators are available with the same syntax and precedence. Arithmetic expressions can be used to as an argument expansion or as a separate command. In addition there is an arithmetic for command that works like the for statement in C.
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.
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:
on the system where your code works.
What is the output from those same commands on the system where it doesn't work?
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.
To solve the problem, set LC_ALL=C.
Thanks,
Adithya
Last edited by Adithya Gokhale; 08-14-2015 at 06:56 AM..
These 2 Users Gave Thanks to Adithya Gokhale For This Post:
Hello,
I am new to shell scripting and getting the error "arithmetic syntax error" on line 55 of my script.
Below is line 55 and 56
Backup=$ (( $Year*365+$Day ))
if ] then PrevHostname=$Hostname; PrevBackup=$Backup
Error:
./mksysbChk.ksh: line 56: *365+as : arithmetic syntax... (10 Replies)
i am having a varialbe a , which is input to my file
i want to multiply this input with value .43, and assign it to variable b.
i tried it as below:
#!/bin/sh
a=$1
b=`expr $1\*0.43`
echo b=$b
error : expr: non-integer argument
Please tell me , how to do this.
Thanks (10 Replies)
I am trying to perform arithmetric, for example, to increment the value of variable $a (say 3) by 0.05 but when I tried the following expression
let a=a+0.05
or a=$((a+0.05))
both returned
3.0499999999999998
I want to keep 2 decimal places so it returns 3.05 instead. (6 Replies)
For numbers between 0 and 1 the below logic is not working.
Output of above shall be "correct" but its echoing "incorrect".Kindly suggest
a=.1
if
then
echo correct
else echo incorrect
fi
Video tutorial on how to use code tags in The UNIX and Linux Forums. (3 Replies)
hi,
i have a bash script that i want to receive a a string from another bash file. But because the string has a dot in the middle it gives me an error. The error is in this line:
let valor=$1
and the value passed is rules.txt
the error is:
let: valor=rules.txt: syntax error: invalid... (2 Replies)
Hi all,
Iīve already searched the forum but canīt find what i am doing wrong.
I am trying to compare two variables using ksh under red hat. The error I get is:
-ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 `
MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Im trying to compare two numbers with decimals but its not working as expected.
a=1
b=1.1
if
then echo "equal"
fi
When I do this it says that the numbers are equal. Ultimately Im using -le and -ge in the if statements but I tested with -eq for simplicity.
Any way to make this... (3 Replies)
Hi Gurus,
I wrote a small KSH script, in that i am comparing two variables like this
curr_time = date +%h.%m
set_time=23.55
If ];
then
zip the file
fi
The above script is croned to run evey 5(3,8,.......,58) minutes, but it is zipping at 23.03 hours. My intention is at 23.58 .what... (4 Replies)