if-else construct not working

Hi all,

    Sorry to ask this easy question but I am stuck. In a scenario i am executing one shell script which contains a if - else construct :

if [ $var -eq 0 ]; then
echo $line
$line >> successful_build.txt
else
$line >> failed_services.txt
fi

explaination : if the value of variable is equals to zero , the content of line variable is appended to a file called successful_build.txt else it is to be appended to another file called failed_services.txt.

when I am executiong the script all commands are working properly but shell is showing an message no file or directory exists with this name. It is not able to create the file either of two.
Even if I explicitly create the file it not able to append the data in the file it remains blank. Any guess ? please help. Thanks in advance.

Try this

f [ $var -eq 0 ]; then
    echo $line >> successful_build.txt
else
    echo $line >> failed_services.txt
fi

Is the script maybe running as a different user / in a different directory so that it doesn't have access privileges for the files?

thanks for the reply but it is not working same problem persists this console does not show any error mssg.

@pludi I am simply running a script which all permissions and simply creating a text file in the same directory.

How are you setting the variable $var? Is this borne shell? Please submit all of the code.

I am storing the execution status of a command in the var variable. The snippet goes like this :

#running ant command
ant -f ../../../build.xml

#storing the ant command execution status
var=`echo $?`

#if ant executes successfully file name stores to success file
#or else file name stored into failed file. (line has read from another files assume it workes fine and it contains a file name simply)
if [ $var -eq 0 ]; then
echo $line
echo $line >> successful_build.txt;
echo $?
else
echo $line >> failed_services.txt
fi

so this is it is.