all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* a minor patch to awk invocation
@ 2014-06-04 18:12 Greg Minshall
  2014-06-06 16:52 ` Eric Schulte
  0 siblings, 1 reply; 12+ messages in thread
From: Greg Minshall @ 2014-06-04 18:12 UTC (permalink / raw)
  To: emacs-orgmode

hi.  i just wandered down a rathole others could avoid.  the following
program fails in (what was to me) a mysterious way:
----
#+BEGIN_SRC awk :var a=2
BEGIN{print $a;}
#+END_SRC
----

it turns out values for variables to awk need to be strings (rather than
a number, as above).  below is a patch to give what might be a less
mysterious error message.

also: for an awk invocation with ":var a=b", all occurrences of "$a" in
the body of the awk code are changed to "b".  i'm curious why this is
done rather than invoking awk with "-v a=b"?  or, moving the
initialization into a "BEGIN{}" block?  maybe because of the variety of
awk variants loose in the world?

cheers, Greg
----
diff --git a/lisp/ob-awk.el b/lisp/ob-awk.el
index ed98afd..162ddfb 100644
--- a/lisp/ob-awk.el
+++ b/lisp/ob-awk.el
@@ -47,6 +47,8 @@
 (defun org-babel-expand-body:awk (body params)
   "Expand BODY according to PARAMS, return the expanded body."
   (dolist (pair (mapcar #'cdr (org-babel-get-header params :var)))
+    (if (not (stringp (cdr pair)))
+	(error "awk variable values must be strings"))
     (setf body (replace-regexp-in-string
                 (regexp-quote (format "$%s" (car pair))) (cdr pair) body)))
   body)

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-06-13  6:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-04 18:12 a minor patch to awk invocation Greg Minshall
2014-06-06 16:52 ` Eric Schulte
2014-06-07  5:42   ` Greg Minshall
2014-06-07  5:46   ` Greg Minshall
2014-06-07 15:15     ` Eric Schulte
2014-06-07 19:05       ` Greg Minshall
2014-06-07 10:32   ` Achim Gratz
2014-06-07 15:17     ` Eric Schulte
2014-06-07 16:22       ` Achim Gratz
2014-06-07 17:00         ` Eric Schulte
2014-06-07 17:57           ` Achim Gratz
2014-06-13  6:37             ` Achim Gratz

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.