diff options
author | zimbatm <zimbatm@zimbatm.com> | 2016-06-12 18:11:37 +0100 |
---|---|---|
committer | zimbatm <zimbatm@zimbatm.com> | 2016-06-12 18:11:37 +0100 |
commit | 28fa4a2f03e2232d95dec9dc2b8ef40857d725db (patch) | |
tree | 60a16516608d1b34c78b1a19bfdac0c9188f8412 /lib/strings.nix | |
parent | 852e9c309638c3e1c0e611c70a2b443d52455aca (diff) |
Escape all shell arguments uniformly
Diffstat (limited to 'lib/strings.nix')
-rw-r--r-- | lib/strings.nix | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index 9e9bdd6e1535..653317ed1716 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -213,7 +213,16 @@ rec { escapeShellArg "so([<>])me" => "so\\(\\[\\<\\>\\]\\)me" */ - escapeShellArg = lib.escape (stringToCharacters "\\ ';$`()|<>\t*[]"); + escapeShellArg = arg: + lib.escape (stringToCharacters "\\ ';$`()|<>\t*[]") (toString arg); + + /* Escape all arguments to be passed to the Bourne shell. + + Example: + escapeShellArgs ["one" "two three"] + => "one two\\ three" + */ + escapeShellArgs = concatMapStringsSep " " escapeShellArg; /* Obsolete - use replaceStrings instead. */ replaceChars = builtins.replaceStrings or ( |