6 Replies - 1593 Views - Last Post: 26 January 2013 - 11:41 PM Rate Topic: -----

#1 -Nix-  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 14-December 11

"fi" unexpected error

Posted 26 January 2013 - 10:06 PM

Here is my code. I have to put it in picture because im new to shell and i really dont know how to copy text out of my putty application, bare with me. Im not sure why im getting this error... i need all of my "fi" commands from my understanding. The code is supposed to either accept one perimeter as a directory and tell you which program has the most lines in it. If no perimeters then it defaults to root "."

It throws this error:
./maxline.sh: line 13: syntax error at line 27: 'fi' unexpected

Posted Image

Also there are some more lines above t he ERROR variable, but its all personal information for school that i cut out, so the numbers for the syntax errors are off a few lines.

Is This A Good Question/Topic? 0
  • +

Replies To: "fi" unexpected error

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,203
  • Joined: 21-June 11

Re: "fi" unexpected error

Posted 26 January 2013 - 10:19 PM

View Post-Nix-, on 27 January 2013 - 06:06 AM, said:

Here is my code. I have to put it in picture because im new to shell and i really dont know how to copy text out of my putty application


If you select text in Putty, it automatically gets copied to the clipboard.

Quote

It throws this error:
./maxline.sh: line 13: syntax error at line 27: 'fi' unexpected


You have an if (that's supposed to be a fi) right before the fi, it's complaining about, so it sees if fi without a condition in between and gets confused.
Was This Post Helpful? 0
  • +
  • -

#3 -Nix-  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 14-December 11

Re: "fi" unexpected error

Posted 26 January 2013 - 10:50 PM

Sorry i know thats supposed to be a FI statement, i took it out for testing and accidentally put an IF, good catch. but i still get a syntax error at line 26: 'fi' unexpected.
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,203
  • Joined: 21-June 11

Re: "fi" unexpected error

Posted 26 January 2013 - 10:53 PM

You also have an elif that's supposed to be an else. If that still doesn't help, copy and paste your code here (now that you know how to copy from putty), so I can play around with it (without having to retype the code from the screenshot).
Was This Post Helpful? 1
  • +
  • -

#5 -Nix-  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 14-December 11

Re: "fi" unexpected error

Posted 26 January 2013 - 11:00 PM


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"
# Verify that either no arguments or one argument exists.
if [[ $# -gt 1 ]]
       then
                printf "$ERROR1"
                exit 1
    fi
DIR="."
# Case #2 and 3.
if [[ $# -eq 1 ]]
        then
                # Is the directory entry a directory?
                   if [[ -d $1 ]]
                        then
                        # Assign $1 to variable DIR when a different directory is searched. .
                                DIR="$1"

                        elif
                               printf "$ERROR2"
                               exit 2
                fi
fi

# All case are processed with the following code.


cd $DIR


# Assign file name with highest number of new lines to the variable FILE.

FILE=$(wc -l `ls` 2>/dev/null | sort -bn | tail -n 2 | head -n 1)

echo $FILE
# Print statement for all cases.

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




Was This Post Helpful? 0
  • +
  • -

#6 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,203
  • Joined: 21-June 11

Re: "fi" unexpected error

Posted 26 January 2013 - 11:11 PM

You still have the elif in there. If I replace that with else, it runs fine.
Was This Post Helpful? 1
  • +
  • -

#7 -Nix-  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 14-December 11

Re: "fi" unexpected error

Posted 26 January 2013 - 11:41 PM

Awesome its working, that else threw me off =\ Thanks guys your the best!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1