这是我关于堆栈溢出的上一个问题的后续问题。我会将脚本缩减为基本部分,但如果这样认为,了解脚本的作用可能会有所帮助,您可以研究其他问题。
#!/usr/bin/env bash
set -eu -o pipefail
declare -a framelist
#Print all results
function output_values() {
echo "Results!";
}
#parsing information from stdin
function parser () {
while read tc;
do
if [ -z "$tc" ]; then
continue
fi
#Evaluation and saving result to array
echo $result_value;
framelist+=($result_value);
if (( <<some abort condition>> )); then
exec 0>&-
echo "Last result: $result_value";
return 0
fi
done
}
some_command_writing_to_stdout | parser $2;
output_values;
Run Code Online (Sandbox Code Playgroud)
该脚本执行命令并将输出通过管道传输到我的本地函数,该函数最终按echo "Last result: $result_value";预期返回该行的结果。此后,它将终止提供在此函数中解析的数据的命令 - 这也有效。 …