toShellVar
lib.strings.toShellVar
Docs pulled from | This Revision | 22 minutes ago
Translate a Nix value into a shell variable declaration, with proper escaping.
The value can be a string (mapped to a regular variable), a list of strings (mapped to a Bash-style array) or an attribute set of strings (mapped to a Bash-style associative array). Note that "string" includes string-coercible values like paths or derivations.
Strings are translated into POSIX sh-compatible code; lists and attribute sets assume a shell that understands Bash syntax (e.g. Bash or ZSH).
Inputs
name
-
1. Function argument
value
-
2. Function argument
Type
string -> (string | listOf string | attrsOf string) -> string
Examples
toShellVar
usage example
''
${toShellVar "foo" "some string"}
[[ "$foo" == "some string" ]]
''