2
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?

1

1 Answer 1

4

Ask Emacs:

  • C-h i to open info
  • g(eshell)for loop to open the node on for loops in eshell

or

  • M-x info-display-manual RET eshell RET
  • gfor loop

There it says:

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}
6
  • I tried for pid in { ps -ef | grep "chrome" | awk '{print $2}' } {kill $pid};unfortunately it doesn't work.
    – Nick
    Commented Dec 25, 2014 at 10:23
  • 1
    You need grep "chrome" - in the pipe here. See also masteringemacs.org/article/complete-guide-mastering-eshell for more eshell information. Commented Dec 25, 2014 at 12:34
  • @AndrewSwann I tried grep "chrome" - and it doesn't work.
    – Nick
    Commented Dec 25, 2014 at 14:31
  • When you say "unfortunately it doesn't work", what exactly do you mean?
    – user2005
    Commented Dec 25, 2014 at 16:43
  • @Nick: see my updated answer for something that ought to work.
    – user2005
    Commented Dec 25, 2014 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.