iterator: повторение одной команды для разных аргументов
- #!/usr/bin/bash
- # iterator COMMAND [ARGS..] --- [ITEMS_TO_BE_ITERATED..]
- declare -a COMMAND iteration_items
- target="COMMAND"
- for argument in "$@"; do
- if [[ "$target" == "COMMAND" && "$argument" == "---" ]]; then
- target="iteration_items"
- continue
- fi
- if [[ "$target" == "COMMAND" ]]; then
- COMMAND+=( "$argument" )
- else # target == iteration_items
- iteration_items+=( "$argument" )
- fi
- done
- for item in "${iteration_items[@]}"; do
- "${COMMAND[@]/\{\}/$item}"
- done