ob-shell-test.org 2.2 KB

a collection of examples for ob-shell tests

Sample data structures

one
two
three
first one
second two
third three
bread 2 kg
spaghetti 20 cm
milk 50 dl

Array tests

Generic shell: no arrays

echo ${array}
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.

echo ${array}
one

Associative array tests (simple map)

Generic shell: no special handing

The shell will see all values as a single string.

echo ${table}
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.

echo ${table[second]}
two

Associative array tests (more than 2 columns)

Generic shell: no special handing

echo ${table}
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.

echo ${table[spaghetti]}
20 cm