posix shell compatible

This commit is contained in:
boyska 2023-09-22 02:57:30 +02:00 committed by itec78
parent 5bfb73ce04
commit f429df01a6

View file

@ -1,27 +1,31 @@
#!/bin/bash #!/bin/sh
set -eu set -eu
num=$1 num="$1"
minlength=1 minlength=2
vowels='aeiou'
consonantics='bcdfglmnprstvz'
alphabets=(bcdfglmnprstvz aeiou) v="$num"
numalpha=${#alphabets[@]}
v=$num
st=
length=0 length=0
st=
idx=$(((numalpha - 1) % numalpha)) idx=1
while ! { [ "$v" -eq 0 ] && [ $idx -eq $(((numalpha - 1) % numalpha)) ] && [ $length -ge $minlength ] ; } while [ "$v" -ne 0 ] || [ $idx -ne 1 ] || [ $length -lt $minlength ]
do do
al=${alphabets[idx]} if [ "${idx}" -eq 1 ]; then
r=$((v % ${#al})) al="$vowels"
v=$((v / ${#al})) idx=0
st="${al:$r:1}$st" else
al="$consonantics"
idx=1
fi
len="${#al}"
r=$((v % len + 1))
v=$((v / len))
st="$(echo "$al" | cut -c "$r")$st"
idx=$(((idx + numalpha - 1) % numalpha)) length=$((length + 1))
length=$((length + 1))
done done
echo "$st" echo "$st"