Unix: I want capture the output of top into variable instead of file -
i want capture output of top variable instead of file.
and tried below
top -n 1 -b | head > top_op echo "inside: $top_op" $top_op | grep cpu > cpu echo "$cpu"
but output just
inside:
if want store output variables, use command substitution:
top_op=$(top -n 1 -b | head) echo "inside: $top_op" cpu=$(echo "$top_op" | grep cpu) echo "$cpu"
using backquotes $()
more recommended recursive without quoting.
top_op=`top -n 1 -b | head`
Comments
Post a Comment