0

I have problem to correctly display results from variable. When I use code as below then results are in one line as below.

httpd=`ps -wweo uname,pid,pcpu,pmem,args | sed -e 's|/usr/pw/apache/bin/httpd.*|httpd|' | grep -E -w 'httpd' | grep -v 'grep' | grep -v 'sed' | sed -r 's/[[:blank:]]+/;/g'` 

echo $httpd
user;6374;0.0;0.0;httpd user;12571;0.0;0.0;httpd user;26473;0.0;0.0;httpd user;29933;0.0;0.0;httpd user;31980;0.1;0.0;httpd

Without variable results are OK and this is what I execpted

  ps -wweo uname,pid,pcpu,pmem,args | sed -e 's|/usr/pw/apache/bin/httpd.*|httpd|' | grep -E -w 'httpd' | grep -v 'grep' | grep -v 'sed' | sed -r 's/[[:blank:]]+/;/g'
    user;6374;0.0;0.0;httpd
    user;12571;0.0;0.0;httpd
    user;22984;0.0;0.0;httpd
    user;26473;0.0;0.0;httpd
    user;29933;0.0;0.0;httpd

Is there any trick to fix my results? Thank you

majan
  • 125
  • 12
  • BTW, when you write `PS` all-uppercase, people read it to mean "powershell". The UNIX `ps` utility is called `ps`, all-lowercase. – Charles Duffy Dec 12 '22 at 16:43
  • 1
    Strictly speaking it's not `echo` stripping the extra characters, it's bash performing Word Splitting on those characters before setting arguments for `echo`. See [here](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) for example to explain when and why to put quotes around a variable. – tjm3772 Dec 12 '22 at 16:45

0 Answers0