题目:抓出某个域的进程号,然后作为这句命令($ sudo ./profiler.sh -d 60 -f 2.svg <pid>)的pid入参,从而达到一句执行的目的。
1. 用反引号:sudo ./profiler.sh -d 60 -f 2.svg `ps -ef|grep oca|awk '{print $2}'|head -1`
反引号作用:反引号括起来的字符串被shell解释为命令行,在执行时,shell首先执行该命令行,并以它的标准输出结果取代整个反引号(包括两个反引号)部分
2. 用xargs:ps -ef|grep oca|awk '{print $2}'|head -1|xargs sudo ./profiler.sh -d 60 -f 2.svg