Use the printf -v convention to give output variable as argument
to escape () function so no subshell needs to be executed for
escaping input. The '-v' option to escape () is just syntactic
sugar for better understanding.
Also, backslash is now escaped with another backslash for emacs. This
ie especially important at the end of string.
`echo` is no longer used to write escaped output -- it might interpret
the escapes itself.
+# escape: "expand" '\' as '\\' and '"' as '\"'
+# calling convention: escape -v var "$arg" (like in bash printf).
+ local __escape_arg__=${3//\\/\\\\}
+ printf -v $2 '%s' "${__escape_arg__//\"/\\\"}"
-
- OPTARG="${OPTARG-none}"
- OPTARG="$(escape "${OPTARG}")"
+ escape -v OPTARG "${OPTARG-none}"
case "${opt}" in
--help|h)
case "${opt}" in
--help|h)
# Positional parameters.
for arg; do
# Positional parameters.
for arg; do
- arg="$(escape "${arg}")"
ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")"
done
ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")"
done