【发布时间】:2011-07-11 19:24:17
【问题描述】:
我正在尝试执行以下操作:
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
但是增量不起作用,变量c 保持为“1”。
我见过this thread,但它不适用于我的情况——当我尝试它时,会出现语法错误。
【问题讨论】: