LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 04-18-2012, 12:53 AM   #16
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374

Hi,

I guessing that the file2="/var${file:32}" part isn't working as expected. As chrism01 mentioned you can use the basename command or, staying with your idea:
Code:
#!/bin/bash

find $1 -type f | while read file
do
file2="/var/www/${file##*/}"
if diff $file $file2 >/dev/null ; then
    rm $file
else
    echo Different
fi
done
Also have a look at the find command. Using -type f makes sure you don't include possible directories.

Hope this helps.
 
Old 04-18-2012, 12:12 PM   #17
dwlamb
LQ Newbie
 
Registered: Apr 2012
Posts: 4

Rep: Reputation: Disabled
Discovered the difference in using
Code:
#!/bin/sh
Instead of
Code:
#!/bin/bash
Changed my script header to the latter and all is working well.

Quote:
Originally Posted by chrism01 View Post
Sounds very odd; have you considered amending debug to
Code:
set -xv
and using basename http://linux.die.net/man/1/basename instead of the bash string fn.
Possibly you have a space or other invisible char in a filename somewhere?

Last edited by dwlamb; 04-18-2012 at 07:05 PM. Reason: add clarity
 
Old 04-18-2012, 06:14 PM   #18
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
That could do it; each shell is slightly different, which is why (at least for prod scripts) I always(!) specify the shell I want explicitly.
Its also not unknown for 'sh' to in fact be a symlink to a different shell ....
 
  


Reply

Tags
bash, compare, files, forward, procmail, spamassassin, vacation


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
shell script to recursively "compare" all files in a directory... silex_88 Programming 3 05-12-2007 04:24 AM
shell script to compare filese b/w local and remote and delete files from local serve dsids Linux - Networking 9 08-23-2006 07:20 AM
Bash script to compare dir contents Boffy Programming 2 08-02-2005 06:08 AM
Compare installed RPM versions using Bash script jimwelc Linux - Newbie 6 01-28-2005 10:40 AM
bash script to rm all files in a dir keirobyn Programming 8 07-19-2002 07:53 AM


All times are GMT -5. The time now is 07:56 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration