emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Greg Minshall <minshall@acm.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: a minor patch to awk invocation
Date: Fri, 06 Jun 2014 12:52:21 -0400	[thread overview]
Message-ID: <871tv2ezaf.fsf@gmail.com> (raw)
In-Reply-To: 6157.1401905539@greg-minshalls-mbp.local

Greg Minshall <minshall@acm.org> 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)

  reply	other threads:[~2014-06-06 17:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-04 18:12 a minor patch to awk invocation Greg Minshall
2014-06-06 16:52 ` Eric Schulte [this message]
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=871tv2ezaf.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=minshall@acm.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).