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,26 +1,30 @@
#!/bin/bash
#!/bin/sh
set -eu
num=$1
minlength=1
alphabets=(bcdfglmnprstvz aeiou)
numalpha=${#alphabets[@]}
v=$num
st=
num="$1"
minlength=2
vowels='aeiou'
consonantics='bcdfglmnprstvz'
v="$num"
length=0
st=
idx=$(((numalpha - 1) % numalpha))
while ! { [ "$v" -eq 0 ] && [ $idx -eq $(((numalpha - 1) % numalpha)) ] && [ $length -ge $minlength ] ; }
idx=1
while [ "$v" -ne 0 ] || [ $idx -ne 1 ] || [ $length -lt $minlength ]
do
al=${alphabets[idx]}
r=$((v % ${#al}))
v=$((v / ${#al}))
st="${al:$r:1}$st"
if [ "${idx}" -eq 1 ]; then
al="$vowels"
idx=0
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))
done