From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [babel] Calling source blocks with arguments Date: Tue, 29 Mar 2011 07:59:53 -0600 Message-ID: <87ipv2rowq.fsf@gmail.com> References: <878vw58pqy.fsf@nzebook.haselwarter.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=41841 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4ZoO-0002C1-A7 for emacs-orgmode@gnu.org; Tue, 29 Mar 2011 10:22:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q4ZkW-0006gn-9L for emacs-orgmode@gnu.org; Tue, 29 Mar 2011 10:18:25 -0400 Received: from mail-iw0-f169.google.com ([209.85.214.169]:35129) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q4ZkW-0006gg-5K for emacs-orgmode@gnu.org; Tue, 29 Mar 2011 10:18:24 -0400 Received: by iwg8 with SMTP id 8so299568iwg.0 for ; Tue, 29 Mar 2011 07:18:23 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Philipp Haselwarter Cc: emacs-orgmode@gnu.org Philipp Haselwarter 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 =C2=AB:results output=C2=BB for the whole file? > Yes, see http://orgmode.org/manual/Buffer_002dwide-header-arguments.html Cheers -- Eric > > thanks,