I'm baffled by something in a small script I wrote. The purpose of the script is to compare 2 files on a system. Somehow a tree structure was copied and am fairly certain that the files are identical

The command line is as follows:

/filecomp.sh /home/daniel/Documents/workspace/www/

This is the script:

find $1 -name "*.*" | while read file
do
    file2="/var${file:32}"
    if diff $file $file2 >/dev/null ; then
      rm $file
    else
      echo Different 
    fi
done

The variable file2 is defined by stripping out the path defined in $1 and adding '/var' to the front of it. The path would become /var/www/ and the same filename.
If I run the file with bash -x to echo the steps for debugging, it works fine. If I don't debug, then I receive an error of Bad Substition at line 10 (the last line of the script).

If you put #!/bin/bash (wherever bash is for you) as the first line in the script, do you still get the error?

Yes, that syntax is included. I merely did not present it here for the sake of brevity.

Member Avatar for b1izzard

Does find command return any error message?

There was something, I don't know what, in the code. Something I couldn't figure out. Rewrote the file from scratch and now it works fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.