Let's say I have this text in a file:
/home is where the heart is.
If for example, I select the /home text, using C-spc, is there a way of sending it to ls, so that in the end if will execute ls /home? M-| does not work.
As far as I know, there is no way to do that in Emacs directly. But everyting is possible with help of elisp:
(defun region-as-argument-to-command (cmd)
(interactive "sCommand: ")
(shell-command
(format
"%s %s"
cmd
(shell-quote-argument
(buffer-substring (region-beginning)
(region-end))))))
shell-quote-argument to the second and third arguments to format, or else be careful never to call this function when the region text includes ;rm -rf /.Try
M-| xargs ls. That is, pass "xargs ls" as the shell command on the region selected.
See xargs.
M-|isshell-command-on-regionwhich pipes the current region into a command. That won't work. Victor's solution should solve your problem.