我想在我的awk代码中将mystatus shell变量更新为新值。 但我觉得语法不对, 我也尝试过声明或评估,但没有任何作用 嗨请帮帮我这个
我的代码:
mystatus="resolved" -- shell variable
awk 'BEGIN { print "<table>" } -- awk code to write in new file
{
print "<tr><td>" $1 "</td><td>" $2 "</td><tr>"
if ($1=="stopped") mystatus="problem" -- change shell variable value
}
END { print "</table>" }' filestats.txt > email.html
echo $mystatus -- variabe value not getting changed.
答案 0 :(得分:0)
像这样(未经测试):
mystatus="resolved" # shell variable
awk '
BEGIN { print "<table>" } # awk code to write in new file
{
print "<tr><td>" $1 "</td><td>" $2 "</td><tr>"
if ($1=="stopped") {
mystatus="mystatus.txt"
print "problem" > mystatus # write to a file instead
close(mystatus)
} # I WAS MISSING I WAS MISSING I WAS MISSING I WAS MISSING I WAS MISSING
}
END { print "</table>" }' filestats.txt > email.html
read mystatus < mystatus.txt # read the status from the file
echo $mystatus # variabe value not getting changed.
如果这是从文件读取到变量的任何方式,某些bash纯粹主义者可以发表评论吗?