LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-01-2011, 05:16 AM   #1
oukourj
LQ Newbie
 
Registered: Mar 2011
Posts: 5

Rep: Reputation: 0
Bash mayhem with for loop and variable range


Wow guys I definitely found my mistake... my counter was wrongly initiated, nothing more
Thanks anyway for readers :P


Hi there,
I'm new here but did already use the forum with help of Google to find a lot of answers, so thanks already to all.

Not so good english, sorry for this :P

Here is a little bash script I'm working on cygwin, I think it will be easy for you to help me :

Code:
count=3
for param in $3 $4 $5 $6 $7 $8 $9 ; do 
	if [ ! -z $param ] ; then
		file[$count]=${param/$1/$2}
		let "count += 1"
		echo Array contains : ${file[*]} #debugging line
	fi
done
echo ${file[1]} #debugging lines
echo ${file[2]} #
Now the output is :

Code:
Array contains : v:\data\ascor\loel
Array contains : v:\data\ascor\loel v:\haha
Array contains : v:\data\ascor\loel v:\haha v:\loel
Array contains : v:\data\ascor\loel v:\haha v:\loel v:\jaj
Note that Input one and two are drive letters, and 3-9 are file paths, just to understand this :
Code:
file[$count]=${param/$1/$2}

As you can see on the output of the script, the two 'testing echoes' I do at the end don't print anything.
That's the point, I do NEED this array further in my script.

I'd understand my "param" var is local to the for, but is the other one too ? I tried to use "declare -a file" before the for, but i get same exact result !


Thanks guys, I hope I'll find before my brain melts of attempts...

Last edited by oukourj; 03-01-2011 at 05:32 AM.
 
Old 03-01-2011, 11:15 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by oukourj View Post
found my mistake... my counter was wrongly initiated
WD fixing it yourself, off the 0-reply list now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] [BASH] non-empty variable before loop end, is empty after exiting loop aitor Programming 2 08-26-2010 10:57 AM
Bash script - Test variable against a range spartiati Programming 3 01-29-2010 02:35 AM
Multiple variable for loop (bash) Phier Programming 9 11-24-2009 09:54 AM
Multiple variable for loop (bash) Phier Linux - Newbie 2 11-23-2009 12:13 PM
Using a variable to control a BASH for loop JohnE1 Programming 15 07-04-2009 04:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:36 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