How to remove the last element from an array in Bash

2 Answers

0 votes
arr=(a b c d e)

unset arr[-1] 

echo ${arr[@]} 



# run:
#
# a b c d
#

 



answered Feb 12, 2021 by avibootz
0 votes
arr=(a b c d e)

unset arr[${#arr[@]}-1]

echo ${arr[@]} 



# run:
#
# a b c d
#

 



answered Feb 12, 2021 by avibootz

Related questions

2 answers 370 views
2 answers 347 views
1 answer 314 views
1 answer 248 views
1 answer 195 views
1 answer 269 views
1 answer 288 views
...