Solution to proverb in Bash
This commit is contained in:
25
bash/proverb/proverb.sh
Normal file
25
bash/proverb/proverb.sh
Normal 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
|
||||
Reference in New Issue
Block a user