LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-19-2011, 09:52 AM   #1
Tech109
LQ Newbie
 
Registered: Jan 2011
Posts: 12

Rep: Reputation: 0
Shell Script - Use variable in a for loop with directory path


I modified files in several directories, and need to run a diff on the backup I created before modifying the file.

I'm trying to compose a simple shell script to speed up the task, but getting a syntax error.

Here is what I have:

for i in DIR1 DIR2 DIR3 DIR4 DIR5 do;
diff /maindir/subdir/subdir/$i/filename.txt.old /maindir/subdir/subdir/$i/filename.txt;
done

I know the paths are valid, and if I run just the diff command with the actual DIR1 instead of $i it works.

Any suggestions as to what I'm missing?

Thanks in advance.
 
Old 01-19-2011, 09:57 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Posting the exact error text you get would help..

You have a misplaced semicolon.
Code:
for i in DIR1 DIR2 DIR3 DIR4 DIR5; do
diff /maindir/subdir/subdir/$i/filename.txt.old /maindir/subdir/subdir/$i/filename.txt;
done
 
1 members found this post helpful.
Old 01-19-2011, 10:22 AM   #3
Tech109
LQ Newbie
 
Registered: Jan 2011
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks much! I was initially entering this line by line and thought the problem was with using the variable in the middle of a path within the script.

Of course, as usual, when I am banging my head against the wall trying to figure out why something isn't working...turns out to be a simple oversight/sytnax error/typo!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 05:48 PM
shell script question $variable in loop icecubeflower Linux - Newbie 2 03-31-2009 09:09 AM
Shell script help: How to pass a directory path to the script? dv502 Programming 13 09-10-2008 03:07 AM
Shell variable in Linux is reset after while loop CBenner Programming 7 05-19-2006 09:46 AM
Need shell script to concatenate a string and a variable into a directory name AwesomeMachine Linux - Newbie 2 05-07-2006 03:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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