Jul 21, 2008 #1 rogers42 Technical User Mar 30, 2007 64 CA Hi Folks, I need help to convert a string to integer so I can manipulate the numbers My Korn shell script is as follows typeset -i today=`date +%d` print $today yesterday=$today-1 print $yesterday I get "21 -1" for yesterday Thanks in advance rogers42
Hi Folks, I need help to convert a string to integer so I can manipulate the numbers My Korn shell script is as follows typeset -i today=`date +%d` print $today yesterday=$today-1 print $yesterday I get "21 -1" for yesterday Thanks in advance rogers42
Jul 21, 2008 1 #2 p5wizard IS-IT--Management Apr 18, 2005 3,165 BE See the [tt]let[/tt] builtin command in the [tt]ksh[/tt] man page. [tt]let yesterday=today-1 (( yesterday=today-1 ))[/tt] What you are doing is just string concatenation... HTH, p5wizard Upvote 0 Downvote
See the [tt]let[/tt] builtin command in the [tt]ksh[/tt] man page. [tt]let yesterday=today-1 (( yesterday=today-1 ))[/tt] What you are doing is just string concatenation... HTH, p5wizard
Jul 21, 2008 1 #3 SamBones Programmer Aug 8, 2002 3,186 US In the Korn shell, "[tt]typeset[/tt]" can also force a variable to be an integer. Code: #!/bin/ksh typeset -i TODAY=$(date '+%d') typeset -i YESTERDAY (( YESTERDAY = TODAY - 1 )) print $YESTERDAY Upvote 0 Downvote
In the Korn shell, "[tt]typeset[/tt]" can also force a variable to be an integer. Code: #!/bin/ksh typeset -i TODAY=$(date '+%d') typeset -i YESTERDAY (( YESTERDAY = TODAY - 1 )) print $YESTERDAY
Jul 21, 2008 #4 p5wizard IS-IT--Management Apr 18, 2005 3,165 BE Sambones said: In the Korn shell, "typeset" can also force a variable to be an integer. Click to expand... Granted, but you still need to do the arithmetic with [tt]let[/tt] or the [tt](( ))[/tt] equivalent for [tt]let[/tt] ... HTH, p5wizard Upvote 0 Downvote
Sambones said: In the Korn shell, "typeset" can also force a variable to be an integer. Click to expand... Granted, but you still need to do the arithmetic with [tt]let[/tt] or the [tt](( ))[/tt] equivalent for [tt]let[/tt] ... HTH, p5wizard
Jul 21, 2008 #5 SamBones Programmer Aug 8, 2002 3,186 US Yup, I wasn't contradicting what you said, just adding to it. Of course after making my post, I noticed that he had "typeset -i" in his example already, so I was probably stating what he already knew. Sorry! Upvote 0 Downvote
Yup, I wasn't contradicting what you said, just adding to it. Of course after making my post, I noticed that he had "typeset -i" in his example already, so I was probably stating what he already knew. Sorry!
Jul 27, 2008 #6 PHV MIS Nov 8, 2002 53,708 FR Another way in ksh: yesterday=$(($(date +%d)-1)) Hope This Helps, PH. FAQ219-2884 FAQ181-2886 Upvote 0 Downvote
Jul 28, 2008 #7 dstxaix Programmer Dec 22, 2005 78 US Would it work for the first of the month? Upvote 0 Downvote
Jul 28, 2008 #8 PHV MIS Nov 8, 2002 53,708 FR Would it work for the first of the month? No. Have a look here: faq822-4802 Hope This Helps, PH. FAQ219-2884 FAQ181-2886 Upvote 0 Downvote
Would it work for the first of the month? No. Have a look here: faq822-4802 Hope This Helps, PH. FAQ219-2884 FAQ181-2886