Reputation: 33
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'
Upvotes: 0
Views: 711
Reputation: 180286
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.
Upvotes: 3