用于自动化的Bash脚本 - 未找到命令

时间:2016-07-11 17:47:07

标签: bash sh

我的.bash_profile中有以下内容:

k9 () { for A in $(ps -A | grep $* | sed 's/^\([A-Za-z0-9]*\).*/\1/' ; ) ; do "kill -9  $A"; done  }

该脚本应该grep命令行S *中输入的var获取PID并在每个上执行kill -9。但相反,我得到了这个:

Machine:~ mach$ k1 Chromium
-bash: kill -9  81922: command not found
-bash: kill -9  82009: command not found
-bash: kill -9  82423: command not found
-bash: kill -9  82424: command not found
-bash: kill -9  82560: command not found
-bash: kill -9  82561: command not found
-bash: kill -9  82563: command not found
-bash: kill -9  82608: command not found
-bash: kill -9  85243: command not found
-bash: kill -9  85248: command not found
-bash: kill -9  85321: command not found

提前致谢!

1 个答案:

答案 0 :(得分:2)

您无需引用整个命令。

k9 () {
  for A in $(ps -A | grep $* | sed 's/^\([A-Za-z0-9]*\).*/\1/' ; ) ; do
    kill -9  "$A"
  done
}