Last active
July 13, 2025 03:46
-
-
Save c0des1ayr/3f34ea49acf1e1c34d931d4ffb1afaf6 to your computer and use it in GitHub Desktop.
Bash <4 mapfile implementation (works down to Bash 2.05b)
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
| filemap(){ # custom back-compat implementation of mapfile bc why not | |
| STRIP="f" | |
| ARRAY_NAME="" | |
| [[ $1 = "-t" ]] && STRIP="t" || ARRAY_NAME=$1 | |
| [[ $ARRAY_NAME = "" ]] && ARRAY_NAME=$2 | |
| LINENUM=0 | |
| for((;;)){ | |
| read -r || break | |
| [[ $STRIP = "t" ]] && printf -v "$ARRAY_NAME[$LINENUM]" '%s' "${REPLY%"${_##*[!\\\n]}"}" || printf -v "$ARRAY_NAME[$LINENUM]" '%s' "$REPLY" | |
| ((LINENUM++)) | |
| } | |
| } | |
| #usage: like mapfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment