From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ken Mankoff Subject: Babel, bash, :variables, and tangling Date: Sun, 15 Sep 2019 17:27:52 -0700 Message-ID: <87o8zl6q5z.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:40160) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9es0-0002zl-F6 for emacs-orgmode@gnu.org; Sun, 15 Sep 2019 20:27:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9erz-0008GR-FW for emacs-orgmode@gnu.org; Sun, 15 Sep 2019 20:27:56 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:35087) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i9erz-0008Eq-9y for emacs-orgmode@gnu.org; Sun, 15 Sep 2019 20:27:55 -0400 Received: by mail-pg1-x530.google.com with SMTP id n4so18691484pgv.2 for ; Sun, 15 Sep 2019 17:27:54 -0700 (PDT) Received: from geus3064linuxwsm (161.11.27.136.in-addr.arpa. [136.27.11.161]) by smtp.gmail.com with ESMTPSA id m9sm13331808pjf.11.2019.09.15.17.27.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 15 Sep 2019 17:27:52 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" 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.