I am learning bash scripting and while I was looking on creating myself a spinner while processing something in my script I came across this code in this question:
i=1
sp="/-\|"
echo -n ' '
while true
do
printf "\b${sp:i++%${#sp}:1}"
done
This is what I was looking for: a spinner type that doesn't concatenate, just erases its entry and echos the next character in $sp
I do not understand however how this is working in the
printf "\b${sp:i++%${#sp}:1}"
Could someone elaborate it for me, so I can learn what is going on? From a programming stand point it look like a ternary for loop but after sp:i++
I am lost. I know 1 means to only show one character in the $sp
var.
I do also know this while
is ever ending.
Also worth noting that there are several differences between echo
and printf
as I tried echo
with echo "\b${sp:i++%${#sp}:1}"
that did not provide the same results ...
reference
echo
orprintf
that you are asking about? – ctrl-alt-delor Feb 18 '20 at 19:07