File scripts/export-template-pipe.bash added (mode: 100755) (index 0000000..0ea91d8) |
|
1 |
|
#!/bin/bash |
|
2 |
|
|
|
3 |
|
# This script receives all data item-by-item (all fields of one item followed by |
|
4 |
|
# all fields of another and so on). |
|
5 |
|
# Commented code shows how received data can be collected and accessed. |
|
6 |
|
# |
|
7 |
|
# Usage example: |
|
8 |
|
# dit export - | ./export-template-pipe.bash |
|
9 |
|
|
|
10 |
|
# This function can use $data array to process item fields as key-value pairs. |
|
11 |
|
function process_item() |
|
12 |
|
{ |
|
13 |
|
for key in "${!data[@]}"; do |
|
14 |
|
: |
|
15 |
|
# echo "Key: $key" |
|
16 |
|
# echo "Value: ${data[$key]}" |
|
17 |
|
done |
|
18 |
|
|
|
19 |
|
# Display title or report its absence. |
|
20 |
|
echo "${data[title]:-<no title>}" |
|
21 |
|
} |
|
22 |
|
|
|
23 |
|
# Compose an associative array from key-value pairs. |
|
24 |
|
declare -A data |
|
25 |
|
while read -rd $'\0' line; do |
|
26 |
|
if [ -z "$line" ]; then |
|
27 |
|
process_item |
|
28 |
|
unset data |
|
29 |
|
declare -A data |
|
30 |
|
continue |
|
31 |
|
fi |
|
32 |
|
|
|
33 |
|
# echo "Line: $line" |
|
34 |
|
key="${line%%=*}" |
|
35 |
|
value="${line#*=}" |
|
36 |
|
# echo "Key: $key" |
|
37 |
|
# echo "Value: $value" |
|
38 |
|
|
|
39 |
|
data[$key]="$value" |
|
40 |
|
done |
File scripts/export-template.bash added (mode: 100755) (index 0000000..a2795ee) |
|
1 |
|
#!/bin/bash |
|
2 |
|
|
|
3 |
|
# This script is invoked once for each item. |
|
4 |
|
# Commented code shows how received data can be collected and accessed. |
|
5 |
|
# |
|
6 |
|
# Usage example: |
|
7 |
|
# dit export ./export-template.bash |
|
8 |
|
|
|
9 |
|
declare -A data |
|
10 |
|
|
|
11 |
|
# Compose an associative array from key-value pairs. |
|
12 |
|
for arg; do |
|
13 |
|
# echo "Arg: $arg" |
|
14 |
|
key="${arg%%=*}" |
|
15 |
|
value="${arg#*=}" |
|
16 |
|
# echo "Key: $key" |
|
17 |
|
# echo "Value: $value" |
|
18 |
|
|
|
19 |
|
data[$key]="$value" |
|
20 |
|
done |
|
21 |
|
|
|
22 |
|
# Visit each array entry. |
|
23 |
|
for key in "${!data[@]}"; do |
|
24 |
|
: |
|
25 |
|
# echo "Key: $key" |
|
26 |
|
# echo "Value: ${data[$key]}" |
|
27 |
|
done |
|
28 |
|
|
|
29 |
|
# Display title or report its absence. |
|
30 |
|
echo "${data[title]:-<no title>}" |