Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-18-2012, 01:53 AM   #16
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390


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:

find $1 -type f | while read file
if diff $file $file2 >/dev/null ; then
    rm $file
    echo Different
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, 01:12 PM   #17
LQ Newbie
Registered: Apr 2012
Posts: 4

Rep: Reputation: Disabled
Discovered the difference in using
Instead of
Changed my script header to the latter and all is working well.

Originally Posted by chrism01 View Post
Sounds very odd; have you considered amending debug to
set -xv
and using 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 08:05 PM. Reason: add clarity
Old 04-18-2012, 07:14 PM   #18
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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 ....


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 05: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 08:20 AM
Bash script to compare dir contents Boffy Programming 2 08-02-2005 07:08 AM
Compare installed RPM versions using Bash script jimwelc Linux - Newbie 6 01-28-2005 11:40 AM
bash script to rm all files in a dir keirobyn Programming 8 07-19-2002 08:53 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:20 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration