Skip to content

Instantly share code, notes, and snippets.

@Th3Fanbus
Created May 28, 2023 08:00
Show Gist options
  • Save Th3Fanbus/3a743dc1829e49d000027c531c213529 to your computer and use it in GitHub Desktop.
Save Th3Fanbus/3a743dc1829e49d000027c531c213529 to your computer and use it in GitHub Desktop.
POSIX-compatible looping over
#!/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