OILS / ysh / testdata / array-rewrite-1.sh View on Github | oilshell.org

43 lines, 14 significant
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
8argv() { spec/bin/argv.py "$@"; }
9
10#
11# OLD, BASH-COMPATIBLE WAY
12#
13
14regex=(old1 old2)
15flags=()
16
17for r in "${regex[@]}"; do
18 flags[${#flags[@]}]="--regex=$r"
19done
20
21argv "${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
34shopt -s simple_word_eval parse_at
35
36var regex2 = %(new1 new2)
37var flags2 = %()
38
39for r in @regex2; do
40 append "--regex=$r" (flags2)
41done
42
43argv @flags2