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
How to pass Shell script variable to awk HIMANI UNIX for Dummies Questions & Answers 3 07-16-2007 01:23 AM
looping through a variable in a shell script ramachandranrr Shell Programming and Scripting 1 03-04-2007 08:02 PM
transfer a variable in a shell script? fedora Shell Programming and Scripting 11 09-22-2006 01:56 PM
problem in getting the path of environment variable set in bashrc in my shell script krithika Shell Programming and Scripting 8 05-26-2006 09:19 AM
How to Pass variable to shell Script sam70 UNIX for Dummies Questions & Answers 5 08-23-2005 08:27 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 09-17-2007
communicator communicator is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 1
Problem in incrementin a variable in UNIX shell script

I have a simple query
If we have BATCH= 081675
and incremnting it by one as
BATCH=`expr ${BATCH} + 000001`;

We can't get BATCH = 081676
but gets BATCH = 81676

Can anyone tell why i am getting this value and not the rquired one and how i could get the required one?
  #2 (permalink)  
Old 09-17-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Because you are operating with integers, not with strings.
I suggest you to perform all the computations with integers and, only at the end, pad the result with the required zeroes (in this case, 6 zeroes):


Code:
BATCH=081675
BATCH=`expr ${BATCH} + 1`
BATCH=`printf "%06d\n" "$BATCH"`
echo "$BATCH"

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 06:04 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