From: Ken Mankoff <mankoff@gmail.com>
To: Org-Mode mailing list <emacs-orgmode@gnu.org>
Subject: Babel, bash, :variables, and tangling
Date: Sun, 15 Sep 2019 17:27:52 -0700 [thread overview]
Message-ID: <87o8zl6q5z.fsf@gmail.com> (raw)
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.
reply other threads:[~2019-09-16 0:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=87o8zl6q5z.fsf@gmail.com \
--to=mankoff@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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).