Skip to content

Instantly share code, notes, and snippets.

@nxnev

nxnev/sample Secret

Created February 22, 2018 13:41
Show Gist options
  • Save nxnev/dae306158fc65471172c5814b49aad35 to your computer and use it in GitHub Desktop.
Save nxnev/dae306158fc65471172c5814b49aad35 to your computer and use it in GitHub Desktop.
#!/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