emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [babel] Calling source blocks with arguments


From: Eric Schulte
Subject: Re: [O] [babel] Calling source blocks with arguments
Date: Tue, 29 Mar 2011 07:59:53 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Philipp Haselwarter <address@hidden> 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,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]