-
-
Save nxnev/dae306158fc65471172c5814b49aad35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
args=() | |
main() { | |
local 'arg' | |
if (( "${#args[@]}" > 0 )); then | |
printf 'Operands:\n' | |
for (( arg = 1; arg <= "${#args[@]}"; arg++ )); do | |
printf ' %d: [%s]\n' "${arg}" "${args[arg-1]}" | |
done | |
fi | |
} | |
batch() { | |
local 'file' | |
for file; do | |
if [[ "${file}" == '-' ]]; then | |
file='/dev/fd/0' | |
fi | |
if [[ ( -c "${file}" || -f "${file}" ) && -r "${file}" ]]; then | |
mapfile -O "${#args[@]}" -t 'args' < "${file}" | |
fi | |
done | |
} | |
while [[ "${1++}" ]]; do | |
case "${1}" in | |
( '-b' | '--batch' ) | |
batch "${2}" | |
shift | |
;; | |
( '--' ) | |
args+=( "${@:2}" ) | |
break | |
;; | |
( * ) | |
args+=( "${1}" ) | |
;; | |
esac | |
shift || break | |
done | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment