From: Tobias Ulmer Date: Fri, 29 Jun 2012 19:39:13 +0000 (+0200) Subject: Introduce e2lib.shquote() to quote strings that are passed to a shell X-Git-Tag: e2factory-2.3.12rc1~34 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=78ea8fbf82378443dd5610f483afa2a55f3fe75e;p=e2factory.git Introduce e2lib.shquote() to quote strings that are passed to a shell Signed-off-by: Tobias Ulmer --- 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