LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Shell Script - Use variable in a for loop with directory path (https://www.linuxquestions.org/questions/linux-general-1/shell-script-use-variable-in-a-for-loop-with-directory-path-857286/)

Tech109 01-19-2011 09:52 AM

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.

AlucardZero 01-19-2011 09:57 AM

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


Tech109 01-19-2011 10:22 AM

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!


All times are GMT -5. The time now is 08:37 PM.