Created
June 30, 2022 19:17
-
-
Save sevenissimo/26b023c26c3574961cd09138d1eca043 to your computer and use it in GitHub Desktop.
Positional arguments handling on Bash scripts
This file contains hidden or 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 | |
| __iterate_on_args() { | |
| for a; do echo "arg: $a"; done | |
| } | |
| __iterate_on_glob() { | |
| #shopt -o nullglob | |
| for f in *."${1:-sh}"; do | |
| echo "file: $f" | |
| done | |
| } | |
| __iterate_on_files() { | |
| : "${1:?Missing operand}" | |
| for f; do if [[ -f "$f" ]]; then | |
| echo "file: '$f'" | |
| else echo "$0: '$f' is not a valid file" >&2 | |
| fi done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment