2017-09-22 121 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,以確保您處理空格和引號正確,當你傳遞參數。