0

I want to check if .todo.txt is empty or not. If is is empty, I want to add the echo in the file, and if it already has content, I want to do something else.

I tried:

hasData()
{
    echo "Hello"
}

isEmpty()
{
    echo -e "$n\t$comment\t$dueD/$dueM/$dueY " >> .todo.txt   
}

if [ -s $file ] ; then
    hasData()
else
    isEmpty()
fi

When I run above code, I get the following:

./todo.sh: line 25: syntax error near unexpected token `else'
./todo.sh: line 25: `   else'
0

1 Answer 1

3

when i run my code i get the following ./todo.sh: line 25: syntax error near unexpected token else' ./todo.sh: line 25: else'

You must use parentheses to define a shell function, but they have no part in calling one. A shell function is invoked just like any other command:

if [ -s $file ] ; then
    hasData
else
    isEmpty
fi

If your functions took arguments, then you would list them after the function name -- again, just like for any other command.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.