From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg Minshall Subject: a minor patch to awk invocation Date: Wed, 04 Jun 2014 21:12:19 +0300 Message-ID: <6157.1401905539@greg-minshalls-mbp.local> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsFfo-00063j-GV for emacs-orgmode@gnu.org; Wed, 04 Jun 2014 14:12:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WsFff-0002ch-Kg for emacs-orgmode@gnu.org; Wed, 04 Jun 2014 14:12:28 -0400 Received: from relay02.pair.com ([209.68.5.16]:4005) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1WsFff-0002cG-En for emacs-orgmode@gnu.org; Wed, 04 Jun 2014 14:12:19 -0400 Received: from greg-minshalls-mbp.local (localhost [127.0.0.1]) by gregair.cliq.com (Postfix) with ESMTP id BFE6C42D4850F for ; Wed, 4 Jun 2014 21:12:19 +0300 (EEST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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)