如何使用bash将多行标准输出写入文件作为多行文本?

比方说,我执行了名为a.py的python程序,它会打印出以下内容:

2 3
3 4
4 5

,我想编写此多行输出,就像将每个输入文件的文件分开一样。 这是我到目前为止尝试过的:

for file in $1/*
do
    case "$file" in
        *".in") echo
            fileformat="p"
            echo "using $file"
            outputfile="$file$fileformat"
            data=$(python3 a.py $file)
            result="$data"
            echo "Write to $outputfile"
            echo $result >>  $outputfile
            ;;
        *)  ;;
    esac
done

现在,我将所有内容写入了一行,而不是所需的多行输出:

2 3 3 4 4 5

我在做什么错了?

zyai558 回答:如何使用bash将多行标准输出写入文件作为多行文本?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3129657.html

大家都在问