emacs-orgmode
[Top][All Lists]
Advanced

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

Re: How to get a table into a variable in a shell code block?


From: Michael Welle
Subject: Re: How to get a table into a variable in a shell code block?
Date: Sun, 04 Apr 2021 07:26:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hello,

William Denton <wtd@pobox.com> writes:

> On 3 April 2021, Greg Minshall wrote:
>
>> #+begin_src shell :results output :var n=numbers
>> echo ${n[1]}
>> #+end_src
>
> Aha, it's in an array but I didn't see it!  Thanks.  Org was doing it magic 
> but
> I got confused by bash.
interestingly I asked a similar question in #org-mode yesterday. I came
up with this approach:

* table test
** user data
#+name: userdata
| uid | name | foo   | bar  |
| a2s | a2   | afoo  | abar |
| b2s | b2   | bfoo  | bbar |
| c2s | c2   | c foo | cbar |

** code
#+begin_src sh :var userdata=userdata :separator , :results raw
  echo "$userdata" | while read line ; do
      IFS=','
      echo "$line" | while read u n f b ; do
          echo "u: $u n: $n f: $f b: $b"
      done
  done
#+end_src

This looks a bit clumsy, but should also work with shell that doesn't
support (2D) array type variables.

Regards
hmw



reply via email to

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