The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
counting the packets damn_bkb IP Networking 2 11-17-2006 07:55 AM
Counting and sort bobo UNIX for Dummies Questions & Answers 4 05-23-2006 08:02 PM
counting characters plelie2 Shell Programming and Scripting 6 02-25-2003 01:38 PM
Counting LOC in C amatsaka High Level Programming 1 06-04-2002 03:18 PM
Counting time black69star Shell Programming and Scripting 2 12-11-2001 11:42 AM

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 07-17-2007
Kenada Kenada is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 2
Counting up a variable

Hello,

I am trying to write a shell script, but i encountered a problem I cant solve alone so I hope you guys can help me. The situation is:

I have a script file and a config file, in my config file I set some Variables:
for example:
destination=(xp, xq, xt)
username=testor
password=testian
file1=html/de/sa_logs.php
file2=html/fr/frappi

the amount of files can go between 1 and xy.

Now the part of the scriptfile i have problems with:
i=1
b=1
while [ $i -le ${#destination[*]} ]
do
echo i ist $i
i=`expr $i + 1`
while [ $b -le ${lineCount} ]
do
t=${file$b} <<-- Here it should get me html/de/sa_logs.php for the first run (b=1) and html/fr/frappi for the second run (b=2)
temp=$t
path=${sourcepath}${temp}
echo ${path}
b=`expr $b + 1`
done
b=1
done
What i need to do is combine file and $b so that the scrip still knows i am talking about the file1, file2,file3,filexy variables and not just some text. No Idea how I can do that. Sorry for my english it isnt my native language.

Hope you can help
  #2 (permalink)  
Old 07-17-2007
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,301
You can use arrays in a loop to get the filenames, it's even better to put the filenames in a file.
To loop through an array you can do something like this:

Code:
file[1]=html/de/sa_logs.php
file[2]=html/fr/frappi

sourcepath="/home/"

for name in ${file[@]}
do
	path="$sourcepath""$name"
	echo $path
done
To read the names from a file "filenames":

Code:
sourcepath="/home/"

while read name
do
	path="$sourcepath""$name"
	echo $path
done < filenames

Regards
  #3 (permalink)  
Old 07-18-2007
Kenada Kenada is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 2
Thank you very much for your reply, it works now.

good day
  #4 (permalink)  
Old 07-18-2007
bigearsbilly bigearsbilly is offline
Registered User
  
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
if you have a file with variables

x=y
y=twenty
z="(1,2,3)"


you can just dot them in.

. varfile

and these variables will be instantiated to the values given, easy.

is that what you mean?
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:22 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