shell管道的bash别名引发错误

时间:2015-10-22 11:18:39

标签: macos bash alias piping

在重新加载Microsoft用户数据库后,我从https://superuser.com/questions/401133/pipe-output-of-awk-to-kill-9调整了以下管道命令以退出所有 Microsoft好东西

ps -Acx | grep Microsoft | awk '{print $1}' | xargs kill

这是广告宣传的,但是当我使用别名

psm="ps -Acx | grep Microsoft | awk '{print $1}' | xargs kill"

我收到很多错误,例如

kill: illegal process id: ??<br>
kill: illegal process id: 0:05.40<br>
kill: illegal process id: Microsoft<br>
kill: illegal process id: Excel<br>
kill: illegal process id: ??<br>
kill: illegal process id: 0:00.04<br>
kill: illegal process id: Microsoft<br>
kill: illegal process id: AU<br>
kill: illegal process id: Daemon<br>
kill: illegal process id: ??<br>
kill: illegal process id: 0:17.95<br>
kill: illegal process id: Microsoft<br>
kill: illegal process id: PowerPoint<br>

有人可以解释这里出了什么问题吗?

Thx - Harald -

1 个答案:

答案 0 :(得分:1)

你应该引用$ in alias

psm="ps -Acx | grep Microsoft | awk '{print \$1}' | xargs kill"