i need diff understanding :)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting i need diff understanding :)
# 1  
Old 09-30-2009
i need diff understanding :)

Can someone tell me where i'm going wrong

Code:
if [ "$file1" \< "$file2" ]; then                 
     set outPut = diff "$file1" "$file2" | wc -l
     echo $file1 $file2;
     echo "$outPut"
        if [$outPut == 0];then
                echo " "$file1" and "$file2" " v
         fi
fi

This is the following result:

Quote:
./Assgn1.bash: line 52: [: missing `]'
0
file txt.txt~

./Assgn1.bash: line 52: [: missing `]'
./Assgn1.bash: line 40: [: too many arguments
0
txt txt.txt

line 52 is referring to the "if [$output = 0]; then"
and line 40 refers "if [ ! -f $file2 ]; then" which is not listed.
# 2  
Old 09-30-2009
It's missing spaces after [, before ]



Code:
if [ "$file1" \< "$file2" ]; then                 
     set outPut = diff "$file1" "$file2" | wc -l
     echo $file1 $file2;
     echo "$outPut"
        if [ $outPut == 0 ];then
                echo "$file1 and $file2" v
         fi
fi



I don't really know what \< means!
# 3  
Old 10-01-2009
i've checked all the white spaces but I still can't see where else the problem is this what i have now

Code:
                if [ ! -f $file1 ]; then
                   continue
                   fi
                for file2 in *
                  do
                  if [ ! -f $file2 ]; then
                     continue
                     fi

		#//checks if file1 is being compared to another different file; not itself
                if [ "$file1" \< "$file2" ]; then 
                     set outPut = `diff "$file1" "$file2" | wc -l`
                     if [ $outPut == 0 ]; then
                         echo " "$file1" and "$file2" " # // prints file if same content
                     fi
                fi

Again the error message is

Quote:

line 62: [: ==: unary operator expected
./forYourEyesOnly.bash: line 50: [: untitled: binary operator expected
./forYourEyesOnly.bash: line 55: [: untitled: binary operator expected
62: refers to if [ $outPut == 0 ]; then
50. refers to if [ ! -f $file1 ]; then
55. refers to if [ ! -f $file2 ]; then

White spaces again?
# 4  
Old 10-01-2009
I've never heard of the '\<' operator before (line 60 by your reckoning). Could you explain that one?
# 5  
Old 10-01-2009
For line 62 it might be that one of the files does not exist, or that one of the variables $file1 or $file2 are not declared (I can't see where $file1 is declared in your script).

Use
Code:
outPut = $(diff $file1 $file2 2>/dev/null | wc -l)
if [ $outPut == 0 ]; then
...

or better
Code:
diff $file1 $file2 > /dev/null 2>&1
if [ $? -eq 0 ]; then
...

And it pointless to say
Code:
for file2 in *
do
 if [ ! -f $file2 ]; then
   continue
 fi
...

because if * expands nothing the for-loop is not executed, so you can assume that file2 does exist.

And use "set -n" in your script (ksh - or the equivalent for your shell) to check the syntax without running it to see where the errors are.

(oh, and what is the \< all about?)
# 6  
Old 10-01-2009
Quote:
Originally Posted by taiL
i've checked all the white spaces but I still can't see where else the problem is this what i have now

Code:
                if [ ! -f $file1 ]; then
                   continue
                   fi
                for file2 in *
                  do
                  if [ ! -f $file2 ]; then
                     continue
                     fi

        #//checks if file1 is being compared to another different file; not itself
                if [ "$file1" \< "$file2" ]; then 
                     set outPut = `diff "$file1" "$file2" | wc -l`
                     if [ $outPut == 0 ]; then
                         echo " "$file1" and "$file2" " # // prints file if same content
                     fi
                fi

Again the error message is



62: refers to if [ $outPut == 0 ]; then
50. refers to if [ ! -f $file1 ]; then
55. refers to if [ ! -f $file2 ]; then

White spaces again?
Umm, I have never heard of '<' operator for test command, test being synonym for '['. If you (according to your comment in the code) want to check that you are not comparing a file against itself, use -ef operator of test.

Furthermore, there is no such operator as '==' - if you want to compare numbers, use -eq, for strings the comparison operator is '='.

Regards,

pen
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diff 3 files, but diff only their 2nd column

Guys i have 3 files, but i want to compare and diff only the 2nd column path=`/home/whois/doms` for i in `cat domain.tx` do whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

2. Shell Programming and Scripting

Need your help in understanding this

Hi, I found this in a script and I would like to know how this works Code is here: # var1=PART1_PART2 # var2=${var1##*_} # echo $var2 PART2 I'm wondering how ##* makes the Shell to understand to pick up the last value from the given. (2 Replies)
Discussion started by: sathyaonnuix
2 Replies

3. Shell Programming and Scripting

serach diff filename in diff location using shell scripting

Hi, I am new to shell scripting. please help me to find out the solution. I need a script where we need to read the text file(consists of all file names) and get the file names one by one and append the date suffix for each file name as 'yyyymmdd' . Then search each file if exists... (1 Reply)
Discussion started by: Lucky123
1 Replies

4. Shell Programming and Scripting

.procmailrc and uudeview (put attachments from diff senders to diff folders)

Moderator, please, delete this topic (1 Reply)
Discussion started by: optik77
1 Replies

5. UNIX for Dummies Questions & Answers

understanding {%/*}/

Hi Gurus: I am trying to understand the following line of code.I did enough of googling to understand but no luck.Please help me understand the follow chunk of code: X=$0 MOD=${X%/*}/env.ksh X is the current script from which I am trying to execute. Say if X=test.ksh $MOD is echoing :... (3 Replies)
Discussion started by: vemana
3 Replies

6. Shell Programming and Scripting

need help understanding mv

I just started shell coding and I'm a bit confused on how 'mv' works can someone explain to me how it works and if i did this correctly. Thanks. echo "Enter Name of the first file:" read file1 #echo $file1 if ; then echo "Sorry, file does not exist." exit 1 ... (16 Replies)
Discussion started by: taiL
16 Replies

7. Shell Programming and Scripting

Simulate SVN diff using plain diff

Hi, svn diff does not work very well with 2 local folders, so I am trying to do this diff using diff locally. since there's a bunch of meta files in an svn directory, I want to do a diff that excludes everything EXCEPT *.java files. there seems to be only an --exclude option, so I'm not sure... (3 Replies)
Discussion started by: ackbarr
3 Replies

8. Linux

Understanding a diff file

Hi folks, I am having difficulties in understanding diff file. I would like to know what the following means in a diff file ex: 202a251,253 1,102c120,126 I believe 'a' will be 'append'. Line 202 appended to line 251. but why there is 253 ???. Like the above if any one can tell me how... (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question