(insert "[" (shell-command-to-string "~/lombardi/http_fetch.sh") "]")
如何將參數傳遞給http_fetch.sh函數。這個論點是通過評估得出的(elfeed-entry-link entry)
Lisp語句中的字符串插值
我試着用'在前面,但結束了一個bash錯誤。
(insert "[" (shell-command-to-string "~/lombardi/http_fetch.sh") "]")
如何將參數傳遞給http_fetch.sh函數。這個論點是通過評估得出的(elfeed-entry-link entry)
Lisp語句中的字符串插值
我試着用'在前面,但結束了一個bash錯誤。
使用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如果你不不需要它。
您可以使用format
來插入字符串。
(insert "["
(shell-command-to-string
(format "~/lombardi/http_fetch.sh %s" (elfeed-entry-link entry)))
"]")
正如史蒂夫提到,你應該使用shell-quote-argument
,以確保您處理空格和引號正確,當你傳遞參數。
不要試圖手動引用參數。在生成的shell命令的每個參數上調用'shell-quote-argument'。 (無論您認爲需要或不需要,通常都是很好的做法。) – phils
謝謝!我編輯了答案,包括你的建議。 –