From 78ea8fbf82378443dd5610f483afa2a55f3fe75e Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Fri, 29 Jun 2012 21:39:13 +0200 Subject: [PATCH] Introduce e2lib.shquote() to quote strings that are passed to a shell Signed-off-by: Tobias Ulmer --- generic/e2lib.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 68b575b..cd91d36 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -681,6 +681,16 @@ function chomp(str, chr) end end +--- quotes a string so it can be safely passed to a shell +-- @param str string to quote +-- @return quoted string +function shquote(str) + assert(type(str) == "string") + e2lib.logf(4, "e2lib.shquote(%s)", str) + str = string.gsub(str, "'", "'\"'\"'") + return "'"..str.."'" +end + -- determines the type of an archive -- say "z" for gzip, "j" for bzip2, "" for tar archive -- nil is returned for unknown data -- 2.39.5