emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Babel, bash, :variables, and tangling
@ 2019-09-16  0:27 Ken Mankoff
  0 siblings, 0 replies; only message in thread
From: Ken Mankoff @ 2019-09-16  0:27 UTC (permalink / raw)
  To: Org-Mode mailing list

Hi List,

I'm having some trouble getting babel executed in Emacs and scripts that are tangled to behave the same. I think I've distilled it down to an MWE. I'd like to inject

#+NAME: table
| 1 | 2 |
| 3 | 4 |

into a bash workflow where I need each of those 4 items with their respective row and column. That is, redefine the table so that it is:

| x | y | z |
| 0 | 0 | 1 |
| 0 | 1 | 2 |
| 1 | 0 | 3 |
| 1 | 1 | 4 |

I can do this in a babel block like this:

#+NAME: import
#+BEGIN_SRC sh :results output :tangle no :var table=table
rm -f tmpfile
lineno=0
echo "${table}" | while read line; do
  colno=0
  echo ${line} | tr ' ' '\n' | while read entry; do
    echo $lineno "|" $colno "|" $entry >> tmpfile
    colno=$(( $colno + 1 ))
  done
  lineno=$(( $lineno + 1 ))
done

echo ""
cat tmpfile
#+END_SRC

#+RESULTS: import
:
: 0 | 0 | 1
: 0 | 1 | 2
: 1 | 0 | 3
: 1 | 1 | 4

And I can call it with:

#+CALL: import(table=table)

And I get the results I want

But when I tangle it out, the tangled file defines "table" like this:

unset table
declare -A table
table['1']='2'
table['3']='4'

And then the algorithm does not work.

Am I doing something incorrectly here with respect to executing babel blocks inside Emacs v. tangling to external files? Any suggestions how to get similar behavior inside emacs and outside emacs?

Thanks,

  -k.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-09-16  0:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-16  0:27 Babel, bash, :variables, and tangling Ken Mankoff

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