此AWK完全可以正常工作,但是当我将其封装在函数中时,它会导致bash错误,是否可以解决此问题?
ps -auxh | awk '{
tcpu +=$3
tmm+=$4
}
END{
print "Total memory usage: " tmm " % Total cpu usage: " tcpu "%"
}'
function calCPUusage{
ps -auxh | awk '{
tcpu +=$3
tmm+=$4
}
END{
print "Total memory usage: " tmm " % Total cpu usage: " tcpu "%"
}'
}
calCPUusage
语法错误是test.sh:第4行:意外令牌ps'
test.sh: line 4:
ps -auxh |附近的语法错误awk'{
答案 0 :(得分:0)
创建函数的语法错误。使用:
function calCPUusage() {