2017-09-22 119 views
1
(insert "[" (shell-command-to-string "~/lombardi/http_fetch.sh") "]") 

如何将参数传递给http_fetch.sh函数。这个论点是通过评估得出的(elfeed-entry-link entry)Lisp语句中的字符串插值

我试着用'在前面,但结束了一个bash错误。

回答

1

使用concat追加字符串从主叫elfeed-entry-link到外壳命令的末尾得到的:

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

shell-quote-argument保护的情况下,该命令的elfeed-entry-link结果包含shell元字符或空格。 (编辑:删除手动报价原本建议在这里和使用shell-quote-argument而是得益于@phils评论)

还要注意的shell-command-to-string结果将极有可能包括最后的换行符,所以一定要strip it out如果你不不需要它。

+0

不要试图手动引用参数。在生成的shell命令的每个参数上调用'shell-quote-argument'。 (无论您认为需要或不需要,通常都是很好的做法。) – phils

+0

谢谢!我编辑了答案,包括你的建议。 –

0

您可以使用format来插入字符串。

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

正如史蒂夫提到,你应该使用shell-quote-argument,以确保您处理空格和引号正确,当你传递参数。