The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Giving format to a file DebianJ Shell Programming and Scripting 4 03-06-2008 04:08 AM
Giving thanks for a long weekend iBot UNIX and Linux RSS News 0 12-01-2007 08:05 AM
Giving input to a c++ file tonyaim83 Shell Programming and Scripting 2 10-22-2007 10:10 PM
RLOGIN giving problems. vishal_ranjan HP-UX 8 06-28-2007 11:47 AM
Giving others execute privileges FredSmith UNIX for Dummies Questions & Answers 10 01-26-2006 07:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-08-2008
RRVARMA's Avatar
Registered User
 

Join Date: Feb 2008
Location: Bangalore, INDIA
Posts: 27
How to get 07 while giving ((Preyy = yy - 01))

Hi,

I need to get the previous year as 07 instead of just 7. I'm running the following for this..

yy=`date '+%y'`
((Preyy = yy - 01))
echo ${Preyy}

Here, instead of 07 i'm getting 7 as result. Please Help.

Thanks,
RRVARMA
Reply With Quote
Forum Sponsor
  #2  
Old 05-08-2008
RRVARMA's Avatar
Registered User
 

Join Date: Feb 2008
Location: Bangalore, INDIA
Posts: 27
Thumbs up Yes i got it...

i just added this in between...

Preyy=$(printf "%02d" $Preyy)


and now my script goes lik this..

yy=`date '+%y'`
((Preyy = yy - 01))
Preyy=$(printf "%02d" $Preyy)
echo ${Preyy}

Thanks,
RRVARMA
Reply With Quote
  #3  
Old 05-08-2008
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 288
Quote:
Originally Posted by RRVARMA View Post
Hi,

I need to get the previous year as 07 instead of just 7. I'm running the following for this..

yy=`date '+%y'`
((Preyy = yy - 01))
echo ${Preyy}

Here, instead of 07 i'm getting 7 as result. Please Help.

Thanks,
RRVARMA
Code:
#!/usr/bin/ksh
yy=`date '+%y'`
prev=0$(( yy - 1 ))
echo $prev
Reply With Quote
  #4  
Old 05-08-2008
Registered User
 

Join Date: Jul 2006
Posts: 189
Best way to do this

Code:
typeset -R2Z Preyy
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0