summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchim Gratz <Stromeko@Stromeko.DE>2014-06-19 19:23:28 (GMT)
committer Achim Gratz <Stromeko@Stromeko.DE>2014-06-23 18:53:16 (GMT)
commit2685f31a506e368aef86edbb71a5ae15438610ef (patch)
tree5254e830e464ed94b1ab57fa6ff249a4f2aa4ba0
parent4a4dbe16d82b4c8d441e79358003577c1ffdb440 (diff)
downloadorg-mode-2685f31a506e368aef86edbb71a5ae15438610ef.zip
org-mode-2685f31a506e368aef86edbb71a5ae15438610ef.tar.gz
ob-shell: stratify shell variable quoting
* lisp/ob-shell.el: Remove unused defcustom `org-babel-sh-var-quote-fmt'. (org-babel-variable-assignments:bash_array): (org-babel-variable-assignments:bash_assoc): Remove superfluous `mapcar' and double quotes around parameters. (org-babel-sh-var-to-sh): Single-quote the whole string and escape all single quotes in the original string.
-rw-r--r--lisp/ob-shell.el42
1 files changed, 18 insertions, 24 deletions
diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 474a8f2..7d87026 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -45,12 +45,6 @@ passed to `shell-command-on-region'"
:group 'org-babel
:type 'string)
-(defcustom org-babel-sh-var-quote-fmt
- "$(cat <<'BABEL_TABLE'\n%s\nBABEL_TABLE\n)"
- "Format string used to escape variables when passed to shell scripts."
- :group 'org-babel
- :type 'string)
-
(defcustom org-babel-shell-names
'("sh" "bash" "csh" "ash" "dash" "ksh" "mksh" "posh")
"List of names of shell supported by babel shell code blocks."
@@ -113,28 +107,26 @@ This function is called by `org-babel-execute-src-block'."
(defun org-babel-variable-assignments:bash_array
(varname values &optional sep hline)
"Returns a list of statements declaring the values as a bash array."
- (format "unset %s\ndeclare -a %s=( \"%s\" )"
- varname varname
- (mapconcat 'identity
- (mapcar
- (lambda (value) (org-babel-sh-var-to-sh value sep hline))
- values)
- "\" \"")))
+ (format "unset %s\ndeclare -a %s=( %s )"
+ varname varname
+ (mapconcat
+ (lambda (value) (org-babel-sh-var-to-sh value sep hline))
+ values
+ " ")))
(defun org-babel-variable-assignments:bash_assoc
(varname values &optional sep hline)
"Returns a list of statements declaring the values as bash associative array."
(format "unset %s\ndeclare -A %s\n%s"
varname varname
- (mapconcat 'identity
- (mapcar
- (lambda (items)
- (format "%s[\"%s\"]=%s"
- varname
- (org-babel-sh-var-to-sh (car items) sep hline)
- (org-babel-sh-var-to-sh (cdr items) sep hline)))
- values)
- "\n")))
+ (mapconcat
+ (lambda (items)
+ (format "%s[%s]=%s"
+ varname
+ (org-babel-sh-var-to-sh (car items) sep hline)
+ (org-babel-sh-var-to-sh (cdr items) sep hline)))
+ values
+ "\n")))
(defun org-babel-variable-assignments:bash (varname values &optional sep hline)
"Represents the parameters as useful Bash shell variables."
@@ -163,8 +155,10 @@ This function is called by `org-babel-execute-src-block'."
"Convert an elisp value to a shell variable.
Convert an elisp var into a string of shell commands specifying a
var of the same value."
- (format org-babel-sh-var-quote-fmt
- (org-babel-sh-var-to-string var sep hline)))
+ (concat "'" (replace-regexp-in-string
+ "'" "'\"'\"'"
+ (org-babel-sh-var-to-string var sep hline))
+ "'"))
(defun org-babel-sh-var-to-string (var &optional sep hline)
"Convert an elisp value to a string."