1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Example of Oil arrays.
|
4 | #
|
5 | # Adapted from ./linux-4.8.7/scripts/tags.sh
|
6 |
|
7 | # Show args to a command
|
8 | argv() { spec/bin/argv.py "$@"; }
|
9 |
|
10 | #
|
11 | # OLD, BASH-COMPATIBLE WAY
|
12 | #
|
13 |
|
14 | regex=(old1 old2)
|
15 | flags=()
|
16 |
|
17 | for r in "${regex[@]}"; do
|
18 | flags[${#flags[@]}]="--regex=$r"
|
19 | done
|
20 |
|
21 | argv "${flags[@]}"
|
22 |
|
23 |
|
24 | #
|
25 | # NEW OIL WAY
|
26 | #
|
27 | # Things fixed:
|
28 | # - verbose "${a[@]}" becomes @a
|
29 | # - a=() is weird because it doesn't allow spaces around =
|
30 | # - Oil uses var a = %()
|
31 | # - builtin 'append' for appending
|
32 | #
|
33 |
|
34 | shopt -s simple_word_eval parse_at
|
35 |
|
36 | var regex2 = %(new1 new2)
|
37 | var flags2 = %()
|
38 |
|
39 | for r in @regex2; do
|
40 | append "--regex=$r" (flags2)
|
41 | done
|
42 |
|
43 | argv @flags2
|