From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: a minor patch to awk invocation Date: Fri, 06 Jun 2014 12:52:21 -0400 Message-ID: <871tv2ezaf.fsf@gmail.com> References: <6157.1401905539@greg-minshalls-mbp.local> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsxj5-0008W6-Ar for emacs-orgmode@gnu.org; Fri, 06 Jun 2014 13:14:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wsxiw-0002Xl-RU for emacs-orgmode@gnu.org; Fri, 06 Jun 2014 13:14:47 -0400 Received: from mail-qg0-x22c.google.com ([2607:f8b0:400d:c04::22c]:44858) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsxiw-0002Xa-O3 for emacs-orgmode@gnu.org; Fri, 06 Jun 2014 13:14:38 -0400 Received: by mail-qg0-f44.google.com with SMTP id i50so4997959qgf.17 for ; Fri, 06 Jun 2014 10:14:38 -0700 (PDT) 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: Greg Minshall Cc: emacs-orgmode@gnu.org Greg Minshall writes: > 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? > Hi Greg, Thanks for pointing out this shortcoming and for suggesting the command-line variable assignment option. I've just pushed up a patch which changes the behavior of awk code blocks to assign variables on the command line, so the following now work. #+begin_src awk :var a=2 BEGIN{ print a; } #+end_src #+RESULTS: : 2 Thanks, > > 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) > -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D (see https://u.fsf.org/yw)