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

java - How to specify maven bin in eclipse maven plugin? -

Error while updating a record in APEX screen -

single sign on - Logging into Plone site with credentials passed through HTTP -