Blog/content/posts/2024/shell/pure-sh-array.md

510 B

title date draft tags
✴️ Массивы на числом Shell 2024-12-02T11:42:09+03:00 false
shell
linux
tips
development
#!/bin/sh

IFS='|'
STROKE='Firebrick|SeaGreen|Sienna|Blue|Purple|Tomato'
set -f

getNth()  { shift "$(( $1 + 1 ))"; printf '%s\n' "$1"; }
getLast() { getNth "$(( $(length "$@") - 1 ))" "$@"; }
length()  { echo "$#"; }

INDEX=0
while [ $INDEX -le $(expr $(length $STROKE) - 1) ]; do
    echo $(getNth $INDEX $STROKE)

    INDEX=$(expr $INDEX + 1)
done