Bash Spinner - Question about syntax
by Arct1c_f0x from LinuxQuestions.org on (#5F730)
Observe, if you will, the code below.
Code:# Bash, with GNU sleep
spin() {
local i=0
local sp='/-\|'
local n=${#sp}
printf ' '
sleep 0.1
while true; do
printf '\b%s' "${sp:i++%n:1}"
sleep 0.1
done
}
The code above creates a spin animation. I know how to recreate it in several ways using different syntax, but there are two lines that I don't completely understand
1st:
'local n=${#sp}' Does this mean set variable "n" to the number of elements in local array "sp" ?
2nd:
In the printf statement that references the sp char array; What functions do the colons ':' serve?
Thanks.


Code:# Bash, with GNU sleep
spin() {
local i=0
local sp='/-\|'
local n=${#sp}
printf ' '
sleep 0.1
while true; do
printf '\b%s' "${sp:i++%n:1}"
sleep 0.1
done
}
The code above creates a spin animation. I know how to recreate it in several ways using different syntax, but there are two lines that I don't completely understand
1st:
'local n=${#sp}' Does this mean set variable "n" to the number of elements in local array "sp" ?
2nd:
In the printf statement that references the sp char array; What functions do the colons ':' serve?
Thanks.