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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -