Found this snippet of code which uses an array in Bash.
unset var1[@]
for i in {0..23}
do
var1[10#$i]="some data"
done
When setting the element with data, what's that 10#
in front of the element number for?
I know that for showing the total number of elements you can use echo ${#var1[@]}
but I don't think the hash in setting the element has something to do with total size.
In arithmetic expressions, you can use #
to specify base :
$ echo $((2#1110))
14
Using 10#$i
would prevent i=08
from failing with value too great for base
and interpret it as 8
. For 0 .. 23, it's equivalent to just i
.
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.