The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help need to find the length of a variable smr_rashmy Shell Programming and Scripting 7 02-18-2008 06:02 AM
Length of a variable karyn1617 Shell Programming and Scripting 3 02-08-2005 06:41 PM
creating a fixed length output from a variable length input r1500 Shell Programming and Scripting 2 12-03-2003 01:09 PM
How to define two variable in foreach command?? geoquest Shell Programming and Scripting 14 08-22-2002 07:11 PM
Using Grep to Define a Variable cspcspcsp UNIX for Dummies Questions & Answers 1 10-12-2001 01:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-31-2005
cbarker cbarker is offline
Registered User
  
 

Join Date: Mar 2005
Location: Maryland
Posts: 5
define length of variable

I have a variable with a value of "05". When I add one to that variable, using the command: CURR_YY=`expr $CURR_YY + 1`, I get the value of "6", losing the leading zero (which is needed for passing to another script). How do I keep the leading zero?

Thank you!
  #2 (permalink)  
Old 03-31-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
In KSH you can do this as follows:

typeset -R2 -Z CURR_YY=05
echo $CURR_YY

05

(( CURR_YY += 1 ))

echo $CURR_YY

06

Thomas
  #3 (permalink)  
Old 03-31-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
#!/bin/ksh

typeset -Z2 a=6

echo "before->[${a}]"
((a=a+1))
echo "after->[${a}]"

  #4 (permalink)  
Old 03-31-2005
cbarker cbarker is offline
Registered User
  
 

Join Date: Mar 2005
Location: Maryland
Posts: 5
Although we have korn shell here, the first line in our scripts set the environment to bourne shell (.#!/bin/sh), so the typeset command does not work. I apologize for not putting that in the initial posting. I'm still learning
  #5 (permalink)  
Old 03-31-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
#!/bin/sh

a='06'
echo "before->[${a}]"
a=`expr ${a} + 1|sed 's/^/0/'`
echo "after->[${a}]"

  #6 (permalink)  
Old 03-31-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
What happens in the year 2010?
  #7 (permalink)  
Old 04-01-2005
cbarker cbarker is offline
Registered User
  
 

Join Date: Mar 2005
Location: Maryland
Posts: 5
I don't need to use the century in this code, so the code will work as I need it to.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0