emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: Philipp Haselwarter <philipp.haselwarter@gmx.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: [babel] Calling source blocks with arguments
Date: Tue, 29 Mar 2011 07:59:53 -0600	[thread overview]
Message-ID: <87ipv2rowq.fsf@gmail.com> (raw)
In-Reply-To: 878vw58pqy.fsf@nzebook.haselwarter.org

Philipp Haselwarter <philipp.haselwarter@gmx.de> writes:

> Hi,
>
> Is there a way to call a source-block with (positional) arguments, like
> one would do on the command line?
>
> I want to include some shell scripts in a paper and would prefer not
> having to introduce some kind of artificial variables.
>
> So I could just write my scripts inline, like
>
> #+srcname: script.sh
> #+begin_src sh
>   #!/bin/sh
>   echo $0: $@
> #+end_src
>
> and demonstrate their output by calling them
>
> #+call: script.sh("arg1", "arg2") :results output
>
> would produce something like
>
> #+results:
> : script.sh: arg1 arg2
>

This wouldn't work under the current setup, for example, we don't even
write the contents of the sh code block to a temporary file, so $0
wouldn't really mean anything... or actually, this would just return the
file-name of the shell used to evaluate the code block, e.g.,

#+begin_src sh
  echo $0
#+end_src

#+results:
: sh

>
>
> Can this be done?
>

Not currently, however if there is enough interest, it wouldn't be too
hard to add a :cmdline header argument to shell scripts, which would
result in the code block body being written to a temporary file, then
called with the supplied :cmdline arguments.

>
> PS:
> Is there a way to set «:results output» for the whole file?
>

Yes, see http://orgmode.org/manual/Buffer_002dwide-header-arguments.html

Cheers -- Eric

>
> thanks,

      parent reply	other threads:[~2011-03-29 14:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-23 21:56 [babel] Calling source blocks with arguments Philipp Haselwarter
2011-03-28 15:19 ` Philipp Haselwarter
2011-03-28 15:27   ` Rainer M Krug
2011-03-28 15:37   ` Eric S Fraga
2011-03-29 13:59 ` Eric Schulte [this message]

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=87ipv2rowq.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=philipp.haselwarter@gmx.de \
    /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).