简体   繁体   中英

print last 5 values in array bash

How I can print last any number of values by doing something like echo " ${ARRAY[-5:]} "; from 372 454 130 427 793 57 810 808 322 362 705 113 819 12 688 to 322 362 705 113 819 12 688

for i in {1..14}
do
ARRAY+=($((RANDOM%886+0)))
done
echo " ${ARRAY[*]} "

You can use this syntax to print last 5 values from an array:

echo "${ARRAY[@]: -5}"

This will print:

705 113 819 12 688

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM