I'm trying to do the following:
function func() # in practice: logs the output of a code block to a file
{
if [ -z "$c" ]; then
c=1
else
(( ++c ))
fi
tee -a /dev/null
echo "#$c"
}
{
echo -n "test"
} | func
{
echo -n "test"
} | func
But the increment doesn't work, the variable c
stays '1'.
I've seen this thread, but it doesn't work for my case - when I try it, a syntax error appears.