Bash (Scripting) - Get the last element from a List

by
Jeremy Canfield |
Updated: April 21 2023
| Bash (Scripting) articles
Let's say you have an list named fruit that contains the following values.
fruit=(banana apple orange grapes)
Here is how you can return the last item from the list.
echo ${fruit[-1]}
Which in this example should return "grapes".
grapes
Did you find this article helpful?
If so, consider buying me a coffee over at