Hi folks, I am trying to convert one character to a numeric format,
for example :
" 1" to number 1
Ups forgot to tell you .. !!! I am trying to do it with kornshell !!!
Hi folks, I am trying to convert one character to a numeric format,
for example :
" 1" to number 1
Ups forgot to tell you .. !!! I am trying to do it with kornshell !!!
Hi,
I am trying to convert a text character readed from a file, to numeric format in order to compare with another number for example :
the file has this ...
" 1"
I need to compare if that value is greater or equal to 1
I wrote this :
if [ "$duplicate" -ge 1 ]
where duplicate is the file, but it won't treat 1 as number but as string.....
What can i use to convert it !!!!!
Egm ..
First, please don't post your question in two parts in different areas of the forum like that. Post a followup to the original post if you need to add something. I have merged your posts into a single thread.
Now as for your question, you do not need to convery a string to numeric with ksh. It should work. But it sound like you variable "duplicate" is a filename. If so, you need to read the data from the file. If the file contains a single integer you can do this:
read num < $filename
if [[ $num -gt 1 ] ; then
If I have misunderstood, print out the value to see what we're dealing with:
echo duplicate = $duplicate
and post the results as a reply in this thread.
First if all, I am new here and did not know about the threads, but it won't happen again.
The program is working fine, the problem that we had was that we were using " instead of '
thanks
Usually when I need to convert a string into a numeric value for arithmetic reasons, I do the following:
(( myNum=$myNum+0 ))
Hope it helps.