Find the answer to your Linux question:
Results 1 to 6 of 6
Hello everyone, I am having trouble executing a script When I try to, I get this: Line 31: Syntax error near unexpected token fi Line 31: fi Code: if test ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Posts
    3

    [SOLVED] Syntax error near unexpected token fi

    Hello everyone, I am having trouble executing a script

    When I try to, I get this:
    Line 31: Syntax error near unexpected token fi
    Line 31: fi

    Code:
    if test $# = 0
    then
    	echo
    	echo This script requires 1 argument
    	exit
    fi
    
    declare -i fileCount
    declare -i dirCount
    declare -i exeCount
    
    	fileCount=0
    	dirCount=0
    	exeCount=0
    
    for i in $*
    do
            if test -f $1
    	then
    		fileCount=fileCount+1
    	fi
    	if test -d $1
    	then
    		dirCount=dirCount+1
    	fi
    	if test -x $1
    	then 
    		exeCount=exeCount+1
    	fi
    done
    fi
    
    echo Number of Files found=$fileCount
    echo Number of Directories found=$dirCount
    echo Number of Executable Files found=$exeCount

  2. #2
    Just Joined!
    Join Date
    Feb 2009
    Posts
    13
    hi Dan,

    i am not an expert but guess if you remove the very last 'fi' (after done) guess the script will work.

  3. #3
    Just Joined!
    Join Date
    Feb 2009
    Posts
    3
    Quote Originally Posted by iamagui View Post
    hi Dan,

    i am not an expert but guess if you remove the very last 'fi' (after done) guess the script will work.
    Ok, I did it and I still got the error message

    Code:
    if test $# = 0
    then
    	echo
    	echo This script requires 1 argument
    	exit
    fi
    
    declare -i fileCount
    declare -i dirCount
    declare -i exeCount
    
    	fileCount=0
    	dirCount=0
    	exeCount=0
    
    for i in $*
    do
            if test -f $1
    	then
    		fileCount=fileCount+1
    	fi
    	if test -d $1
    	then
    		dirCount=dirCount+1
    	fi
    	if test -x $1
    	then 
    		exeCount=exeCount+1
    	fi
    done
    
    echo Number of Files found=$fileCount
    echo Number of Directories found=$dirCount
    echo Number of Executable Files found=$exeCount

  4. #4
    Just Joined!
    Join Date
    Feb 2009
    Posts
    13
    i copied, pasted and ran your script and it ran without any error(s) for me.

  5. #5
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Which distro are you using? Add #!/bin/bash as first line in the script.
    Code:
    #!/bin/bash
    
    if test $# = 0
    then
    	echo
    	echo This script requires 1 argument
    	exit
    fi
    
    declare -i fileCount
    declare -i dirCount
    declare -i exeCount
    ---- ----
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  6. #6
    Just Joined!
    Join Date
    Feb 2009
    Posts
    3
    Thanks for your help. I was editing the backup file instead of the original one which still had the extra 'fi'. It works fine now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...