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

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 8a37fd in the box below so that we can be sure you are a human.