3
(insert "[" (shell-command-to-string "~/lombardi/http_fetch.sh") "]")

How can I pass an argument to the http_fetch.sh function. This argument is arrived at by evaluating (elfeed-entry-link entry)

I tried using a ' in front but ended up with a bash error.

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80

2 Answers2

2

Use concat to append the string resulting from calling elfeed-entry-link to the end of the shell command:

(insert "["
        (shell-command-to-string
         (concat "~/lombardi/http_fetch.sh " (shell-quote-argument (elfeed-entry-link entry))))
        "]")

The shell-quote-argument protects the command in case the result of elfeed-entry-link contains shell metacharacters or whitespace. (EDIT: removed manual quoting originally suggested here and used shell-quote-argument instead, thanks to the comment from @phils.)

Note also that the result of shell-command-to-string will most likely include a final newline, so be sure to strip it out if you don't want it.

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
  • Don't try to quote the arguments manually. Call `shell-quote-argument` on each argument to a generated shell command. (It is generally good practice to do this whether you think you need to or not.) – phils Sep 23 '17 at 15:16
2

You can use format to interpolate strings.

(insert "["
        (shell-command-to-string
         (format "~/lombardi/http_fetch.sh %s" (elfeed-entry-link entry)))
        "]")

As Steve mentions, you should really use shell-quote-argument to ensure you handle spaces and quotes correctly when you pass the argument.

Wilfred Hughes
  • 29,846
  • 15
  • 139
  • 192