Skip to main content
added 16 characters in body
Source Link
ilkkachu
  • 148.1k
  • 16
  • 268
  • 441

I have a script that needs to format numbers with thousands separators. So 12345671234567 becomes 1,234,5671,234,567. I use printf "%'d" 1234567printf "%'d" 1234567 to get the result. Works fine. Later in the script I set a custom IFS=","IFS="," to process a table of string pairs. If I then use the printf "%'d"printf "%'d" function I don't get commas, I get spaces instead. If I reset IFSIFS back to its default, then printfprintf behaves as expected. Why is IFSIFS affecting the printf formating?

I have a script that needs to format numbers with thousands separators. So 1234567 becomes 1,234,567. I use printf "%'d" 1234567 to get the result. Works fine. Later in the script I set a custom IFS="," to process a table of string pairs. If I then use the printf "%'d" function I don't get commas, I get spaces instead. If I reset IFS back to its default, then printf behaves as expected. Why is IFS affecting the printf formating?

I have a script that needs to format numbers with thousands separators. So 1234567 becomes 1,234,567. I use printf "%'d" 1234567 to get the result. Works fine. Later in the script I set a custom IFS="," to process a table of string pairs. If I then use the printf "%'d" function I don't get commas, I get spaces instead. If I reset IFS back to its default, then printf behaves as expected. Why is IFS affecting the printf formating?

Source Link

Custom IFS changed printf formatting

I have a script that needs to format numbers with thousands separators. So 1234567 becomes 1,234,567. I use printf "%'d" 1234567 to get the result. Works fine. Later in the script I set a custom IFS="," to process a table of string pairs. If I then use the printf "%'d" function I don't get commas, I get spaces instead. If I reset IFS back to its default, then printf behaves as expected. Why is IFS affecting the printf formating?