From: Greg Minshall <minshall@acm.org>
To: emacs-orgmode@gnu.org
Subject: a minor patch to awk invocation
Date: Wed, 04 Jun 2014 21:12:19 +0300 [thread overview]
Message-ID: <6157.1401905539@greg-minshalls-mbp.local> (raw)
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)
next reply other threads:[~2014-06-04 18:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-04 18:12 Greg Minshall [this message]
2014-06-06 16:52 ` a minor patch to awk invocation 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6157.1401905539@greg-minshalls-mbp.local \
--to=minshall@acm.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).