Script running in bash 3.0 not in 3.2

I have wasted one working day writing this scripts.
It compares two folders and make a good tabbed report about their differences.

#!/bin/bash

function DRAW_DEPTH () {
 ROUND=$1
 while [ $ROUND -ge 0 ]
 do
   printf %s "    "
   ROUND=`expr $ROUND - 1`
 done
 printf %s "|- "
}

function MAIN () {
 
 TAB=`DRAW_DEPTH $DEPTH`
 
 DIR_LIST=`ls -l $1 | awk '{print $9}'`
 for i in $DIR_LIST
 do
   # Si es un directorio entonces vamos por aki
   
   if [ -d ${1}/${i} ]; then
     if [ -d ${2}/${i} ]; then
       echo "$TAB (OK) ${1}/${i} is a directory, it exist in ${2}"
       DEPTH=`expr $DEPTH + 1`
       MAIN ${1}/${i} ${2}/${i}
       DEPTH=`expr $DEPTH - 1`
       TAB=`DRAW_DEPTH $DEPTH` 
     else
       echo "$TAB (**) ${1}/${i} is a directory, it does NOT exist in ${2}"
     fi

   else    

     # Si no es un directorio miramos primero si es un LINK
     if [ -h ${1}/${i} ]; then
       if [ -h ${2}/${i} ]; then
         checksum_1=`sum ${1}/${i} | awk '{print $1}'`
         checksum_2=`sum ${2}/${i} | awk '{print $1}'`
         if [ $checksum_1 == $checksum_2 ]; then
           echo "$TAB (OK) $i exists as LINK in $1 and in $2 and they're EQUAL"
         else
           echo "$TAB (@@) $i exists as LINK in $1 and in $2 but they DIFFER"
         fi
       else
         echo "$TAB (**) $i exists as LINK in $1 but does NOT exist in $2"
       fi
     else
       if [ -e ${2}/${i} ]; then
         checksum_1=`sum ${1}/${i} | awk '{print $1}'`
         checksum_2=`sum ${2}/${i} | awk '{print $1}'`
         if [ $checksum_1 == $checksum_2 ]; then
           echo "$TAB (OK) $i exists in $1 and in $2 and they're EQUAL"
         else
           echo "$TAB (@@) $i exists in $1 and in $2 but they DIFFER"
         fi
       else
         echo "$TAB (**) $i exists in $1 but does NOT exist in $2"
       fi
     fi
   fi 
done;
}

DEPTH=-1
MAIN $1 $2

I wrote it while i was working with my RedHat 4-6 with bash interpreter:
GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu)
But here at work i have Ubuntu 8-04 and bash:
GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)

And it doesnt run....:confused:..... someone can tell about what commands have changed or perhaps another problem.

Put "set -x" on the second line of the script, run it again, and post the last few (10 or so) lines of output (before it fails).

+ DEPTH=-1
+ MAIN dir_1/ dir_2/
++ DRAW_DEPTH -1
++ ROUND=-1
++ '[' -1 -ge 0 ']'
++ printf %s '|- '
+ TAB='|- '
++ ls -l dir_1/
++ awk '{print $9}'
+ DIR_LIST=

This is complete output.....

DIR_LIST empty? why? "ls -l" works in all bash versions. Or it isnt the problem?
Thx for "set -x" good !

I think it's because your new version of Linux has an alias or function overriding the ls command. Just to be sure you are using the command and not some alias'd version of it, use:

DIR_LIST=`command ls -l $1 | awk '{print $9}'`

Thats true, in Ubuntu i have an alias ls="ls --color", but unfortunately thats not the problem. I have run the script with your suggestion, and the output remains the same.

Thx again but.....anything else?
Perhaps the name of first argument ..... ./dir_1 dir_1 ./dir_1/
i have tested but its always the same.... plz help!!

What does "ls -l dir_1" give you, please? Then try "ls -l dir_1 |awk '{ print $9}'".

OMG it was simple:

ls -l line in RedHat

ls -l line in Ubuntu

The format of date is different, so awk was taking $9 when it must take $8. Thx Otheus.
I need make this script runable in all platforms so: --->(new thread better?)

How can i get the names of files, links and dirs without depends of platform.??

Well, there you go. Your ls -l command uses a different output format. For some reason in Ubuntu, it's printing out a very non-standard number in the first column. Also, it's printing a full date, as opposed to the traditional UNIX ls date format. Anyway, the awk script should have used "$NF" instead of "$9" as that's (almost) guaranteed to work no matter what.

Will be the name of file always at the end of ls line.
Is that a default UNIX behaviour?

Yes, but all bets are off if the -F option is also specified. Soft-links, for instance, might be shown as:

# command ls -lF
 -rw-r--r-- 1 otheus tisperson 75 Jan 28 11:47 file1
 -rw-r--r-- 1 otheus tisperson 97 Jan 28 11:53 file2
 lrwxrwxrwx 1 otheus tisperson  5 Jan 28 12:46 file3 -> file2

Here, you would get two copies of file2.

For various reasons, in my scripts, I try to use /bin/ls or command ls to make sure I don't pick up stray variants.With Ubuntu, however, it looks like they customized the ls code to make it more Windows like.