Operating System - HP-UX
1821537 Members
2258 Online
109633 Solutions
New Discussion юеВ

Converting string to number in ksh script?

 
SOLVED
Go to solution
MAD_2
Super Advisor

Converting string to number in ksh script?

Can anyone tell me how to convert the result from a series of commands from string to number in order to use these results with arithmetic operands?

i.e.

bdf| grep /tmp | awk '{print $5}'| cut -c1,2

How to I convert the string result to number in a script?

Thanks,
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
3 REPLIES 3
John Carr_2
Honored Contributor
Solution

Re: Converting string to number in ksh script?

Hi

this works

answer=$(bdf | grep /tmp | awk '{print $5}'| cut -c1,2)

expr answer$

John.
John Carr_2
Honored Contributor

Re: Converting string to number in ksh script?

Hi again

what you are trying to do here will fail if the disk uasge is below 10% try this instead

answer=$(bdf| grep /tmp | awk '{print $5}'| sed -e 's/%//g')

expr $answer


John.

MAD_2
Super Advisor

Re: Converting string to number in ksh script?


Thanks John, I did not even think about that possibility, but it certainly wouldn't work in that case.

ADAM
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with