Merge branch 'maint'
[org-mode.git] / testing / examples / ob-shell-test.org
bloba54e5c0d4e706be457f0fa5982b36ad6eb2baf7e
1 #+Title: a collection of examples for ob-shell tests
2 #+OPTIONS: ^:nil
4 * Sample data structures
5 #+NAME: sample_array
6 | one   |
7 | two   |
8 | three |
10 #+NAME: sample_mapping_table
11 | first  | one   |
12 | second | two   |
13 | third  | three |
15 #+NAME: sample_big_table
16 | bread     |  2 | kg |
17 | spaghetti | 20 | cm |
18 | milk      | 50 | dl |
20 * Array tests
21   :PROPERTIES:
22   :ID:       0ba56632-8dc1-405c-a083-c204bae477cf
23   :END:
24 ** Generic shell: no arrays
25 #+begin_src sh :exports results :var array=sample_array
26 echo ${array}
27 #+end_src
29 #+RESULTS:
30 : one two three
32 ** Bash shell: support for arrays
33 Bash will see a simple indexed array. In this test, we check that the
34 returned value is indeed only the first item of the array, as opposed to
35 the generic serialiation that will return all elements of the array as 
36 a single string.
37 #+begin_src bash :exports results :var array=sample_array
38 echo ${array}
39 #+end_src
41 #+RESULTS:
42 : one
44 * Associative array tests (simple map)
45   :PROPERTIES:
46   :ID:       bec1a5b0-4619-4450-a8c0-2a746b44bf8d
47   :END:
48 ** Generic shell: no special handing
49 The shell will see all values as a single string.
50 #+begin_src sh :exports results :var table=sample_mapping_table
51 echo ${table}
52 #+end_src
54 #+RESULTS:
55 : first one second two third three
57 ** Bash shell: support for associative arrays
58 Bash will see a table that contains the first column as the 'index'
59 of the associative array, and the second column as the value.
60 #+begin_src bash :exports results :var table=sample_mapping_table
61 echo ${table[second]}
62 #+end_src
64 #+RESULTS:
65 : two
67 * Associative array tests (more than 2 columns)
68   :PROPERTIES:
69   :ID:       82320a48-3409-49d7-85c9-5de1c6d3ff87
70   :END:
71 ** Generic shell: no special handing
72 #+begin_src sh :exports results :var table=sample_big_table
73 echo ${table}
74 #+end_src
76 #+RESULTS:
77 : bread 2 kg spaghetti 20 cm milk 50 dl
78    
79 ** Bash shell: support for associative arrays with lists
80 Bash will see an associative array that contains each row as a single
81 string. Bash cannot handle lists in associative arrays.
82 #+begin_src bash :exports results :var table=sample_big_table
83 echo ${table[spaghetti]}
84 #+end_src
86 #+RESULTS:
87 : 20 cm