[Top][All Lists]

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

Re: [Orgmode] org-babel : passing variables to sh/screen blocks ?

From: Dan Davison
Subject: Re: [Orgmode] org-babel : passing variables to sh/screen blocks ?
Date: Tue, 23 Feb 2010 11:09:57 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Julien Fantin <address@hidden> 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
  :results: output
  :var: datafromproperty=package-list-1

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

: 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"

: 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.


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

reply via email to

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