File tree Expand file tree Collapse file tree 1 file changed +42
-2
lines changed Expand file tree Collapse file tree 1 file changed +42
-2
lines changed Original file line number Diff line number Diff line change 11# shellcheck disable=SC2148
22#
3- # Various bash helper functions live here.
4-
3+ # Various bash helper fns which aren't used enough to move to just recipes.
54
65# This can be used to simplify ssh sessions, rsync, ex:
76# ssh -o "$(ssm-proxy-cmd "$REGION")" "$INSTANCE_ID"
@@ -34,3 +33,44 @@ submit() (
3433 echo " Transaction $TX_SIGNED with txid $TXID submitted successfully."
3534 echo
3635)
36+
37+ foreach-pair () (
38+ set -euo pipefail
39+
40+ [ -n " ${DEBUG:- } " ] && set -x
41+
42+ if [ " $# " -ne 3 ]; then
43+ echo " Usage:"
44+ echo " foreach-pair \$ STRING_LIST_1 \$ STRING_LIST_2 \$ STRING_CMD"
45+ echo
46+ echo " Where:"
47+ echo " \$ STRING_CMD has \$ i and \$ j embedded as iters from the two lists"
48+ echo
49+ echo " Example:"
50+ echo " foreach-pair \"\$ (just ssh-list name " preview1.* " )\" \"\$ (just ssh-list region " preview1.* " )\" 'just aws-ec2-status \$ i \$ j'"
51+ exit 1
52+ fi
53+
54+ local l1=" $1 "
55+ local l2=" $2 "
56+ local cmd=" $3 "
57+
58+ read -r -a l1 <<< " $l1"
59+ read -r -a l2 <<< " $l2"
60+
61+ if [[ ${# l1[@]} -ne ${# l2[@]} ]]; then
62+ echo " Error: Lists are not the same length." >&2
63+ exit 1
64+ fi
65+
66+ local length=${# l1[@]}
67+
68+ for (( n = 0 ; n < length; n++ )) ; do
69+ # shellcheck disable=SC2034
70+ local i=" ${l1[n]} "
71+ # shellcheck disable=SC2034
72+ local j=" ${l2[n]} "
73+
74+ eval " $cmd " || true
75+ done
76+ )
You can’t perform that action at this time.
0 commit comments