abhishek
(Abhishek Prakash)
1
If you are following the Bash Basics series on It’s FOSS, you can submit and discuss the answers to the exercise at the end of the chapter:
Fellow experienced members are encouraged to provide their feedback to new members.
Do note that there could be more than one answer to a given problem.
Mayor
(Mayor)
2
#!/bin/bash
numbers=()
read -p "Enter 3 numbers: " num
IFS=' ' read -r -a numbers <<< "$num"
numbers_length=${#numbers[@]}
reverse_numbers=()
for (( i=$numbers_length-1; i>=0; i-- )); do
reverse_numbers+=("${numbers[i]}")
done
echo "Numbers in reverse order are: ${reverse_numbers[*]}"
abhishek
(Abhishek Prakash)
3
I liked the use of IFS. I guess I deliberately omitted that from the tutorial.