shell scripting error help

Im tryign to write a script that counts the number of new lines in the file with the most new lines in a given directory

i keep getting this error

/export/home/sieben01/itec400/homework> ./maxlines.sh
./maxlines.sh[12]: syntax error: `then' unexpected operator/operand

any ideas?

#!/bin/ksh

ERROR1="error:can only use 0 or 1 arguments.\nusage:maxlines.sh[directory]"
ERROR2="error:argument must be a Directory.\nusage:maxlines.sh[directory]\n"
if [[ $# -gt 1 ]]
  then
        printf "$ERROR1"
        exit 1
fi
DIR="."
if [[ $# -eq 1]]
   then
        if[[ -d $1 ]]
        then
        DIR="$1"
   else
        printf "$ERROR2"
        exit 1
fi
cd $DIR
FILE=$(wc-l `ls` 2>/dev/null | sort -bn | Tail -n 2 | head -n 1)
printf "File `echo $FILE | awk '{print $2}'` has the maximum lines with `echo $1| awk '{print $1}'` lines.\n"
exit 0

You are missing a 'fi' in your nested if statement.

thanks. fixed that. still getting same error though

if [[ $# -eq 1 ]]   <<----  space after "1"
   then
        if [[ -d $1 ]]  <<---- space after "if" 

there's a typo in your inner if...then:

if [[ $# -eq 1]]
   then
        if[[ -d $1 ]]
        then
        DIR="$1"
   else
        printf "$ERROR2"
        exit 1
fi

should be:

$ if [[ $# -eq 1 ]]
then
   if [[ -d $1 ]]
   then
      DIR="$1"
   else
      printf "$ERROR2"
#     exit 1
   fi
fi
[1]+ [[ 0 -eq 1 ]]
$

THANKS!
it seems to be working. still getting this error though

Tail: not found

lower-case T...tail

ok its working but its not displaying any results. just

/export/home/sieben01/itec400/homework> ./maxlines.sh
File has the maximum lines with lines.

im guessing its in this statement. the awk print statements. should the print $1 and print $2 be changed?

printf "File `echo $FILE | awk '{print $2}'` has the maximum lines with `echo $1| awk '{print $1}'` lines.\n"
exit 0

more typos spotted:

wc-l 

needs to be

wc -l 

;

`echo $1| awk '{print $1}'` lines.\n"

needs to be

`echo $LINE| awk '{print $1}'` lines.\n"

ok almost working. the first part is working just not teh line count

File printnum.sh has the maximum lines with lines.

FILE=$(wc -l `ls` 2>/dev/null | sort -bn | tail -n 2 | head -n 1)
printf "File `echo $FILE | awk '{print $2}'` has the maximum lines with `echo $LINE| awk '{print $1}'` lines.\n"
exit 0

works here...I note that you provide no screenshots to support just how it's not working. You might want to step your way across the pipes to ensure each progressive leg provides what you're looking for...before handing it off to the subsequent print statement.

You might also drop the embedded `ls` and go with a globbed * approach:

wc -l * 2>/dev/null |sort -bn |tail -n 2 |head -n 1

...and switch to simply using print, instead of the printf, which expects arguments...

Good luck.

got it working. thanks guys