emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dan Davison <davison@stats.ox.ac.uk>
To: Julien Fantin <julien.fantin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: org-babel : passing variables to sh/screen blocks ?
Date: Tue, 23 Feb 2010 11:09:57 -0500	[thread overview]
Message-ID: <87fx4s0w8a.fsf@stats.ox.ac.uk> (raw)
In-Reply-To: <e86166cb1002221710t7b23b62dtbf89f936957fe36d@mail.gmail.com> (Julien Fantin's message of "Tue, 23 Feb 2010 02:10:51 +0100")

Julien Fantin <julien.fantin@gmail.com> writes:

> I haven't been able to do so, is it possible ?
>
> I'm trying to make an org file that will take care of fetching and intsalling
> all my required packages, and it would really help in making things more
> streamlined, if shell blocks could source some variables from 'accessible'
> places in the file...
>
> It would be even more convenient if I could use :PROPERTIES: drawers, but I
> wasn't even able to do that in a language other than elisp, so I'm not holding
> my breath here.
>
> Any help will be appreciated though !

Hi Julien,

Yes, you can pass data from org tables to shell blocks just like for
other languages, and you can also use property drawers to hold header
arguments to be inherited by all blocks in the subtree.

Here's a quick example that shows both. It also shows how to slice a
single column out of an org table and pass that to the shell script.

--8<---------------cut here---------------start------------->8---
* Data

#+tblname: package-list-1
| packagename-1-1 |
| packagename-1-2 |

#+tblname: package-list-2
| packagename-2-1 |
| packagename-2-2 |

#+tblname: package-list-3
| Package which does X | packagename-3-1 |
| package which does Y | packagename-3-2 |
| package which does Z | packagename-3-3 |

* Referring to tables in source blocks
  :PROPERTIES:
  :results: output
  :var: datafromproperty=package-list-1
  :END:

*** Tables with one column
#+begin_src sh :var datafromheaderarg=package-list-2
  for package in $datafromproperty ; do
      echo "Installing $package"
  done
  echo
  for package in $datafromheaderarg ; do
      echo "Installing $package"
  done
#+end_src

#+results:
: Installing packagename-1-1
: Installing packagename-1-2
: 
: Installing packagename-2-1
: Installing packagename-2-2

*** Operating on one column of a table

#+begin_src sh :results output :var packages=package-list-3[0:2,1]
  for package in $packages ; do
      echo "Installing $package"
  done
#+end_src

#+results:
: Installing packagename-3-1
: Installing packagename-3-2
: Installing packagename-3-3
--8<---------------cut here---------------end--------------->8---


Actually, with yesterday's org, you will get quoted strings like this:

Installing "packagename-1-1"

That bug is fixed now so you'll need to pull the latest git version.

Dan

>
> Regards, fellow org-moders.
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

      reply	other threads:[~2010-02-23 16:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-23  1:10 org-babel : passing variables to sh/screen blocks ? Julien Fantin
2010-02-23 16:09 ` Dan Davison [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=87fx4s0w8a.fsf@stats.ox.ac.uk \
    --to=davison@stats.ox.ac.uk \
    --cc=emacs-orgmode@gnu.org \
    --cc=julien.fantin@gmail.com \
    /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).