for pid in $(ps -ef | grep "chrome" | awk '{print $2}'); do kill -9 $pid; done
Invalid read syntax: ")"
What's the right way to run this script in Eshell?
for pid in $(ps -ef | grep "chrome" | awk '{print $2}'); do kill -9 $pid; done
Invalid read syntax: ")"
What's the right way to run this script in Eshell?
Ask Emacs:
C-h i
to open infog(eshell)for loop
to open the node on for loops in eshellor
M-x info-display-manual RET eshell RET
gfor loop
Because Eshell commands can not (easily) be combined with lisp forms, Eshell provides a command-oriented `for'-loop for convenience. The syntax is as follows:
`for VAR in TOKENS { command invocation(s) }'
where TOKENS is a space-separated sequence of values of VAR for each iteration. This can even be the output of a command if TOKENS is replaced with `{ command invocation }'.
For your particular problem you have to remember that some commands have been replaced with eshell internals, including kill
. If you can't kill a process with
for pid in { ps -ef | grep "chrome" | awk '{print $2}' } {kill $pid}
try this instead
for pid in { ps -ef | grep "chrome" | awk '{print $2}' } {/usr/bin/kill $pid}
Or possibly better:
for pid in { pgrep "chrome" } {/usr/bin/kill $pid}