[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] Re: [babel] How to kill two birds with one stone?
From: |
Sébastien Vauban |
Subject: |
[O] Re: [babel] How to kill two birds with one stone? |
Date: |
Mon, 28 Feb 2011 16:16:49 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (windows-nt) |
Hi Eric,
"Eric Schulte" wrote:
> I haven't followed this discussion very closely, but I'm not sure why it
> would be necessary to pass data through STDIN rather than through a variable
> or an external file.
>
> I took a shot at the dot graph example you proposed, the following works for
> me over a simple example directory.
For sure, your version works, but it does not address the two goals -- I hope
they don't exclude each other -- I wanna try to reach.
This should clarify the subject.
#+TITLE: graph-dir-eric-schulte
#+DATE: 2011-02-28
#+LANGUAGE: en_US
* Directory to search
#+results: graph-dir
: graph-dir
* List all files in dir
#+source: graph-files
#+begin_src sh :results vector :var dir=graph-dir
find $dir -type f -exec basename {} \;
#+end_src
#+results: graph-files
| dan |
| eric |
| other |
| seb_vauban |
* Association of files with mentions
#+source: graph-associations
#+begin_src sh :var dir=graph-dir :var files=graph-files
for i in $files; do
for j in `grep -l -r $i $dir`; do
echo $i, `basename $j`
done
done
#+end_src
#+results: graph-associations
| dan | eric |
| eric | seb_vauban |
| other | eric |
| other | seb_vauban |
| seb_vauban | dan |
* Ultimate goal
The first goal of this document was to write small snippets of code, with a
clear and concise specification, and test its results when applied on some
input data. This goal is clearly met.
Though, the following goal, the ultimate one, is to be able to output an
independent shell script -- out of this stuff --, so that the program can be
run independently by anybody, just from a simple shell.
How could I write such a "combined" shell script?
Something in the spirit of:
#+source: graph-associations-sh-script
#+begin_src sh :var dir=graph-dir :noweb yes
cd $dir
for i in `<<graph-files>>`; do
for j in `grep -l -r $i $dir`; do
echo $i, `basename $j`
done
done
#+end_src
#+results: graph-associations-sh-script
But, of course (because of the =dir= var?), the above does not work, at least
for my first goal: seeing "in situ" (part of) the results it returns when it
is run.
Maybe it's possible to reach both goals, maybe it's not -- I've no definite
clue about this.
- Maybe we need =stdin= to be properly "handled" for this, nothing more?
- Maybe we need to add some extra hard constraints on how to write the little
program parts, such as "don't use the Babel :var mechanism"?
- Etc...
* Executive summary
To sum up what I'm trying to explain, I'd like the ability to write *and run*
small snippets of code, such as:
#+source: block-1
#+begin_src sh
... do this...
#+end_src
#+source: block-2
#+begin_src sh
... do that...
#+end_src
*and* to be able to produce the shell script that would run them all from a
shell (no need for Emacs), something like:
#+source: full-code
#+begin_src sh :tangle yes
<<block-1>>
<<block-2>>
#+end_src
or
#+source: full-code
#+begin_src sh :tangle yes
<<block-1>> | <<block-2>>
#+end_src
or
#+source: full-code
#+begin_src sh :tangle yes
for i in `<<block-1>>`; do
<<block-2>>
done
#+end_src
or ... (depending on what the code does) ...
Which conditions would allow one to make both dreams true at the same time?
Best regards,
Seb
--
Sébastien Vauban
- [Orgmode] Re: [babel] How to kill two birds with one stone?, (continued)
- [Orgmode] Re: [babel] How to kill two birds with one stone?, Sébastien Vauban, 2011/02/06
- Re: [Orgmode] Re: [babel] How to kill two birds with one stone?, Eric Schulte, 2011/02/20
- [Orgmode] Re: [babel] How to kill two birds with one stone?, Sébastien Vauban, 2011/02/25
- Re: [Orgmode] Re: [babel] How to kill two birds with one stone?, Nick Dokos, 2011/02/25
- Re: [Orgmode] Re: [babel] How to kill two birds with one stone?, Nick Dokos, 2011/02/25
- [O] Re: [babel] How to kill two birds with one stone?, Sébastien Vauban, 2011/02/28
- Re: [Orgmode] Re: [babel] How to kill two birds with one stone?, Eric Schulte, 2011/02/25
- [Orgmode] Closing #+results: with #+end declaration?, Bastien, 2011/02/26
- [Orgmode] Re: Closing #+results: with #+end declaration?, Eric Schulte, 2011/02/27
- [O] Re: Closing #+results: with #+end declaration?, Sébastien Vauban, 2011/02/28
- [O] Re: [babel] How to kill two birds with one stone?,
Sébastien Vauban <=