Welcome to the new Linux Foundation Forum!

Unexpected token fi

lukefrost2014lukefrost2014 Posts: 1
edited January 2015 in Command Line

I am trying to run my command but it comes up with this error:

syntax error near unexpected token `fi' on line 7.

Here is my command:

if [ $# -gt 0 ]
then
if [ $1 = head ] || [$1 = tail ]
then
$1 -n $3
else
fi
fi

if [ -d $3 ]
then
echo "Directory selected exists"
else
echo "Directory selected does not exist"
fi

if [[ $2 = *[[:digit:[[* [[;
then
echo "value is a digit"
else
echo "$2 is not an integer"
fi

Comments

  • saqman2060saqman2060 Posts: 777
    edited December 2014
    I am trying to run my command but it comes up with this error:
    syntax error near unexpected token `fi' on line 7.

    Here is my command:

    if [ $# -gt 0 ]
    then
    if [ $1 = head ] || [$1 = tail ]
    then
    $1 -n $3
    else

    You did not put an action to execute after the else statement. The "else" statement always needs an action in order for the command to execute properly.

    If this is not satisfied, "$1 -n $3, what should the command do as a result?

    fi
    fi

    if [ -d $3 ]
    then
    echo "Directory selected exists"
    else
    echo "Directory selected does not exist"
    fi

    if [[ $2 = *[[:digit:[[* [[;
    then
    echo "value is a digit"
    else
    echo "$2 is not an integer"
    fi
Sign In or Register to comment.