Solution to proverb in Bash

This commit is contained in:
2023-07-15 18:39:44 +02:00
parent 9dea7a1fcc
commit 6d6148d66d
7 changed files with 942 additions and 0 deletions

25
bash/proverb/proverb.sh Normal file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
inputs=("$@")
length=${#inputs[@]}
last_index=$((length - 1))
# Loop through the 'inputs' array, excluding the last element
for ((i=0; i<last_index; i++)); do
current=${inputs[i]}
next=${inputs[i+1]}
# Check if the current element is empty
if [[ -z $current ]]; then
echo "And all for the want of a $next."
else
echo "For want of a $current the $next was lost."
fi
done
# Check if the first element is empty
if [[ -z ${inputs[0]} ]]; then
echo ""
else
echo "And all for the want of a ${inputs[0]}."
fi