Find not working right

if [[ "$1" == "" ]]
 then

leftarray=($(find . -type l -printf "%p\n" 2>/dev/null))
rightarray=($(find . -type l -printf "%l\n" 2>/dev/null))

for var in "${rightarray[@]}"
do
   maximumarray[$index]=`echo "$var" | tr -dc "/" | wc -c | tr -d " "`
   index=$(($index+1))
done
#############
for numbers in "${maximumarray[@]}"
do
   if [[ $numbers > $MAX  ]]
   then
   MAX=$numbers
   fi
done
#############
for var in "${rightarray[@]}"
do

   component=`echo "$var" |  tr -dc "/" | wc -c | tr -d " "`
        if [[ $component -eq $MAX  ]]
        then
        echo "Output: '${leftarray[$temp]} -> ${rightarray[$temp]}'"
        fi
   temp=$(($temp + 1))
done
fi

Here's the problem When running script without arguments or switches it should search through all directories and subdirectories of directory where you are. It does not work and I do not know why and it drives me crazy.

This script should find the symbolic link with longest number of "/" in -printf "%l\n" and output it. It should work when there are more links with same number of "/"

this script have also switch -d <number> and it has the same code as above but in find i use also -maxdepth and it works fine so I do not know why this does not work.

Any help ?

You don't say what happens when it doesn't work.
You don't say what shell you're using and you don't say what OS you're using.

So, as a VERY wild guess, try changing:

#############
for numbers in "${maximumarray[@]}"
do
   if [[ $numbers > $MAX  ]]

to:

#############
MAX=0
for numbers in "${maximumarray[@]}"
do
   if [[ $numbers -gt $MAX ]]

I don't see why -depth would change the results, but using > instead of -gt performs a string comparison instead of a numeric comparison. So, for example 2 > 12 is true while 2 -gt 12 is false.

1 Like

i changed > with -gt and it works thank you
i am using bash2 and running on unix free bsd server
and also max=o is at the beginning of the script
this is only a part of script

but i have another problem

my script must pass through tester

all test are okay except when running script like this
./skript.csh dirctory directory directory

it should search all these three directories and find the longest links it has the same code as above only first if have test -d "$1" if the first argument is directory and in find is "$@" insted of "." and there are two test in these test the tester run script with more directories and first test is ok but second not and i dont know why any idea where can be problem. also there are directories and links with special characters in name or spaces but script work with them good

You have shown us what your code looks like when your script is invoked with no arguments (or with the 1st argument set to an empty string).

You have implied what your code looks like with the 1st argument is "-d".

Show us what code you're using when there are 3 arguments given that name directories.

And, PLEASE, never name a bash script with the filename extension ".csh". The .csh filename extension, by convention, should only be used to name C shell scripts. The Bourne shell (and extensions of the Bourne shell like bash and ksh) are very different from the C shell.