when i was having problems with trying to do arithmetic expansion and then adding it to a variable i decided to see how others had solved this problem.
i seen an unusual expression that i haven’t seen before in others answers. what i would like is more info on it, where i can look it up, what it’s called…
i’ll put mine here –
An=$1
total=0
for ((x=0; x<"${#An}"; x++)); do
total=$(( "$total" + "${An:$x:1}" ** "${#1}" ))
done
it’s what is getting added to the total in braces, the An.... part
when i look at ‘man bash’ AND your ‘hello’ explanation then what the man page was saying makes more sense. i have seen this in some of the basic python that i have played with.
Using the number 153 as a test, the sum of $result should be 153:
1 + 125 + 27=153
Instead, it prints 112527, which is each iteration of the loop with no white space.