I need to use the index i in a loop such as for i in {0..10..5} in a floating-point calculation.What is the simplest way to convert i to floating-point?Variations oni=$(bc -l <<< scale=7;$i)do not work.
Convert bash loop index to floating-point
shell script;floating point
Use bc or awk or a shell with floating point support like ksh93, zsh or yash instead of bash.bc$ bc -l << \EOFheredoc> for (i = 0; i <=  10; i += 2.5) i / 2heredoc> EOF01.250000000000000000002.500000000000000000003.750000000000000000005.00000000000000000000awk$ awk 'BEGIN {for (i = 0; i <= 10; i += 2.5) print i / 2}'01.252.53.755zsh$ float i; for ((i = 0; i <= 10; i += 2.5)) print $((i/2))0.1.252.53.755.ksh93$ for ((i = 0; i <= 10; i += 2.5)); do print $((i/2)); done01.2523.755(beware the decimal separator is locale dependent (. or ,).yashi=0; while [ $((i <= 10)) -ne 0 ]; do  echo $((i / 2))  i=$((i + 2.5))done(inside $((...)) you use . as the decimal separator, but on I/O, the locale's one (. or ,) is used instead).Editnow if you just want to loop over some integers and those integers be represented with a decimal point in them, the just append a .0: for i in {0..10..5}.0Or for the solutions above use printf %.7f\n instead of print/echo to output the numbers with 7 digits after the decimal separator.