开发者

How do I list the output of ps -U root -u root -eo pid in a single line seperated by comma's

开发者 https://www.devze.com 2023-01-19 00:14 出处:网络
when I execute the cmd ps -U root -u root -eo pid I get the output in multiple lines Eg: 1 2 3 4 I would like to see the output in one line as 开发者_StackOverflow中文版1,2,3,4,5 ...One possible wa

when I execute the cmd ps -U root -u root -eo pid I get the output in multiple lines

Eg: 1 2 3 4

I would like to see the output in one line as 开发者_StackOverflow中文版1,2,3,4,5 ...


One possible way is

ps -U root -u root -eo pid | tr -s "\n" ","


No need external command

var=$(ps -U root -u root -eo pid )
echo ${var//$'\n'/,}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号