LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2005, 03:55 PM   #1
steve_f60
Member
 
Registered: Jul 2004
Posts: 43

Rep: Reputation: 15
A Bash Scripting Question


Hello All,

I am writing a script that will create multiple symbolic links based upon which type is needed. The resulting sym link must be named as follows : str7966rgXXX ( where XXX is a 3 digit number from 101 thru 111)

Script I wrote is below but my problem is that I can't get the links named correctly. Instead of having rg101, 102, 103.....110,111 , I get 11, 12,13...18,19,110,111.

How can I maintain the correct numbering with what I have in my script by maintaining the value of x as a 2 digit number? I thought I could use typeset or declare but haven't figured out what configuration would work.


# !/bin/bash

# sf - 5/26/05

x=01

echo " Enter image type store or warehouse , followed by [ENTER]:"

read image
if [ $image = store ]
then

until [ ${x} = 12 ]
do

ln -sf client_golden.master str7966rg1${x}
x=$[$x + 1]
done

fi

if [ $image = warehouse ]
then

until [ ${x} = 12 ]
do

ln -sf GreenScreenwSource.master str7966rg1${x}
x=$[$x + 1]
done

fi

Thanks,

Steve
 
Old 05-26-2005, 04:02 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
"How can I maintain the correct numbering with what I have in my script by maintaining the value of x as a 2 digit number?"

The problem is that you cannot display a leading zero when displaying a variable's value. To solve this problem you could initialize x as x=101 and make the corresponding changes in the rest of the script.

--------------------------
Steve Stites
 
Old 05-26-2005, 04:15 PM   #3
steve_f60
Member
 
Registered: Jul 2004
Posts: 43

Original Poster
Rep: Reputation: 15
Talking

What can I say Steve??????? After I saw your response I realized how stupid I was.... Its the obvious stuff that kills me..............

We'll just keep this to ourselves ok???????

Thanks Much !

Steve F
 
Old 05-26-2005, 06:39 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
"We'll just keep this to ourselves ok???????"

OK.

---------------------------
Steve Stites
 
Old 05-26-2005, 06:57 PM   #5
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
I had a leading zero problem once in bash far more compicated that yours.
Did you know that in bash the leading zero is used to represent octal numbers?

Code:
skalkoto@darkstar:~$ a=08
skalkoto@darkstar:~$ a=$[$a+1]
-bash: 08: value too great for base (error token is "08")
skalkoto@darkstar:~$
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Scripting Question fiod Linux - Newbie 4 11-19-2005 05:09 AM
bash scripting question bmfan Linux - Software 6 11-04-2005 08:54 PM
Bash scripting question. pete1234 Programming 23 09-22-2005 06:52 PM
Bash Scripting Question jsimmonds Programming 2 06-16-2005 09:07 AM
Bash scripting question Hammett Linux - General 4 11-29-2004 06:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration