Created
May 28, 2023 08:00
-
-
Save Th3Fanbus/3a743dc1829e49d000027c531c213529 to your computer and use it in GitHub Desktop.
POSIX-compatible looping over
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 sh | |
# POSIX-compatible scripts cannot use the non-POSIX | |
# `seq` command or any shell-specific functionality. | |
# This is a helper function to make number lists to | |
# be used in for-loops. This is a reduced subset of | |
# the functionality `seq` provides, but is portable. | |
range() { | |
loopcnt=$1 | |
while [ "$loopcnt" -le "$2" ] | |
do | |
echo "$loopcnt" | |
loopcnt=$(( loopcnt + 1 )) | |
done | |
} | |
# Usage example | |
for a in $(range 1 64) | |
do | |
echo $a | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment