【发布时间】:2025-12-23 12:15:12
【问题描述】:
昨天我问了如何将控制台输出保存在文件中的问题(请参阅redirect only last line of STDOUT to a file)。现在我遍历文件,编译它们。这是我的命令:
for REPORT in Test_Basic_*.scala; do
scalac -Xplugin:divbyzero.jar $REPORT | awk 'END{print $REPORT} END{print}' >> output.txt
done
我想保存编译的最后输出和文件名。在上面的例子中,只有 $REPORT 会被保存,但我想引用迭代变量的名称。
例如我有文件 Test_Condition.scala 并运行上面的命令:
for REPORT in Test_Basic_*.scala; do
scalac -Xplugin:divbyzero.jar $REPORT | awk 'END{print $REPORT} END{print}' >> output.txt;
done
然后scalac -Xplugin:divbyzero.jar $REPORT 产生以下输出:
You have overwritten the standard meaning
Literal:()
rhs type: Int(1)
Constant Type: Constant(1)
We have a literal constant
List(localhost.Low)
Constant Type: Constant(1)
Literal:1
rhs type: Int(2)
Constant Type: Constant(2)
We have a literal constant
List(localhost.High)
Constant Type: Constant(2)
Literal:2
rhs type: Boolean(true)
Constant Type: Constant(true)
We have a literal constant
List(localhost.High)
Constant Type: Constant(true)
Literal:true
LEVEL: H
LEVEL: H
okay
LEVEL: H
okay
false
symboltable: Map(a -> 219 | Int | object TestIfConditionWithElseAccept2 | normalTermination | L, c -> 221 | Boolean | object TestIfConditionWithElseAccept2 | normalTermination | H, b -> 220 | Int | object TestIfConditionWithElseAccept2 | normalTermination | H)
pc: Set(L, H)
现在我想在 output.txt 中保存Test_Condition.scala(文件名)和pc: Set(L, H)(编译输出的最后一行)。使用上面的命令,我只保存$REPORT pc: Set(L, H)。
如果这个解释很复杂,请告诉我。感谢您的大力支持。
马蒂亚斯
【问题讨论】: