How can get the value 001 using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can get the value 001 using shell script
# 1  
Old 07-20-2009
How can get the value 001 using shell script

Hi Gurus,

Please help in this shell script.

x=000
y=`expr $x + 1`
echo $y

which gives me the value as 1

How can i get the value as 001 in this shell script. As i am new to scripting stuck up here.

Requesting here help here
# 2  
Old 07-20-2009
Instead of echo use the below...

Code:
printf "%03d" "$y"

# 3  
Old 07-20-2009
You can also use typeset:

Code:
x=0
typeset -Z3 y=$(expr $x + 1)
echo $y
001

Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Simple 'date' to 001 scheme script

So since I'm looking for an easy way to numberize files in a folder according to date: Is there an easy script (batch, windows), that will rename files like this: .earliest creation time: 001.file older creatiin time : 002.file even older time : 003.file .... ... .. . ... (10 Replies)
Discussion started by: pasc
10 Replies

2. UNIX Desktop Questions & Answers

for loop (001 to 500)

hey, how do i create a for loop that runs for i from 001 to 500 ? i need that the zero prefix will remain so when i print "i" it will look like so: 001 002 . . 008 009 . . 058 059 . . 500 please advise. (2 Replies)
Discussion started by: boaz733
2 Replies
Login or Register to Ask a Question