all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob ebd74212aa5ca38c0fafa4e2bc8d506169de1c28 2349 bytes (raw)
name: testing/examples/ob-shell-test.org 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
#+Title: a collection of examples for ob-shell tests
#+OPTIONS: ^:nil

* Sample data structures
#+NAME: sample_array
| one   |
| two   |
| three |

#+NAME: sample_mapping_table
| first  | one   |
| second | two   |
| third  | three |

#+NAME: sample_big_table
| bread     |  2 | kg |
| spaghetti | 20 | cm |
| milk      | 50 | dl |

* Array tests
  :PROPERTIES:
  :ID:       0ba56632-8dc1-405c-a083-c204bae477cf
  :END:
** Generic shell: no arrays
#+begin_src sh :exports results :var array=sample_array
echo ${array}
#+end_src

#+RESULTS:
: one two three

** Bash shell: support for arrays
Bash will see a simple indexed array. In this test, we check that the
returned value is indeed only the first item of the array, as opposed to
the generic serialiation that will return all elements of the array as 
a single string.
#+begin_src bash :exports results :var array=sample_array
echo ${array}
#+end_src

#+RESULTS:
: one

* Associative array tests (simple map)
  :PROPERTIES:
  :ID:       bec1a5b0-4619-4450-a8c0-2a746b44bf8d
  :END:
** Generic shell: no special handing
The shell will see all values as a single string.
#+begin_src sh :exports results :var table=sample_mapping_table
echo ${table}
#+end_src

#+RESULTS:
: first one second two third three

** Bash shell: support for associative arrays
Bash will see a table that contains the first column as the 'index'
of the associative array, and the second column as the value.
#+begin_src bash :exports results :var table=sample_mapping_table
echo ${table[second]}
#+end_src

#+RESULTS:
: two

* Associative array tests (more than 2 columns)
  :PROPERTIES:
  :ID:       82320a48-3409-49d7-85c9-5de1c6d3ff87
  :END:
** Generic shell: no special handing
#+begin_src sh :exports results :var table=sample_big_table
echo ${table}
#+end_src

#+RESULTS:
: bread 2 kg spaghetti 20 cm milk 50 dl
   
** Bash shell: support for associative arrays with lists
Bash will see an associative array that contains each row as a single
string. Bash cannot handle lists in associative arrays.
#+begin_src bash :exports results :var table=sample_big_table
if (( ${BASH_VERSINFO[0]} > 3 )); then
  # understands associative arrays
  echo spaghetti ${table[spaghetti]}
else
  # Default V3.x behavior, has one array item contains the key and values.
  echo ${table[1]}
fi
#+end_src

#+RESULTS:
: spaghetti 20 cm


debug log:

solving ebd7421 ...
found ebd7421 in https://yhetil.org/emacs/CA+p9wPA3q1LO5S4++KrKQRLUd2G4Wr=UQN+wHy0TrZNfcEdqgQ@mail.gmail.com/
found a54e5c0 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 a54e5c0d4e706be457f0fa5982b36ad6eb2baf7e	testing/examples/ob-shell-test.org

applying [1/1] https://yhetil.org/emacs/CA+p9wPA3q1LO5S4++KrKQRLUd2G4Wr=UQN+wHy0TrZNfcEdqgQ@mail.gmail.com/
diff --git a/testing/examples/ob-shell-test.org b/testing/examples/ob-shell-test.org
index a54e5c0..ebd7421 100644

Checking patch testing/examples/ob-shell-test.org...
Applied patch testing/examples/ob-shell-test.org cleanly.

index at:
100644 ebd74212aa5ca38c0fafa4e2bc8d506169de1c28	testing/examples/ob-shell-test.org

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.