Coming from this answer I'm trying to output a sequence of numbers using a dot as a decimal separator.
This works:
$ LANG=en_US seq 0.1 0.1 0.8
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
$ LANG=en_US seq 0.1 0.1 1.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
But this doesn't:
$ LANG=en_US seq 0.1 0.1 0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0,9
Why? How can I fix it?
To prevent any locale settings (such as LC_NUMERIC
, a likely culprit here) from influencing behavior:
LC_ALL=C seq 0.1 0.1 0.9
That said, I don't advise using seq
at all. It's a nonstandard command, not guaranteed to be available on all UNIX platforms or to have any specific behavior when it is available. An a floating-point-capable alternative, consider awk
:
LC_ALL=C awk -v min=0.1 -v max=0.9 -v inc=0.1 \
'BEGIN { cur=min; while (cur <= max) { print cur; cur += inc; }; exit; }'