Skip to main content
added 396 characters in body
Source Link
Graeme
  • 34.6k
  • 9
  • 90
  • 110

No idea why its there, but here's how to disable it with the GNU implementation of bc:

echo '6^6^3' | BC_LINE_LENGTH=0 bc

BC_LINE_LENGTH

This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70.

###Update:

I was confused about this question, I thought it was about the origins of the multi-line feature, it does seem like an odd one. Anyway the real answer is that if you do not quote the variable, the shell will do word splitting on it before this is passed to echo. Word splitting is the process where an expansion is split into 'words' depending on the contents of IFS, these 'words' then become different arguments. In the question example, this creates two arguments to echo, which echo then separates with a space (I knew this before Stephane commented, honest...).

To prevent this happening, just double quote the variable:

num=$(echo '6^6^3' | bc)
echo "$num"

Sometimes this is actually useful as a way to remove IFS characters from a variable (although printf %s is safer for arbitrary strings). Eg (in bash):

$ var=$'spaces:    newlines:\n\n\ntabs:\t\t\t end'

$ echo "$var"
spaces:    newlines:


tabs:            end
$ newvar="$(printf '%s ' $var)"
$ echo "$newvar"
spaces: newlines: tabs: end

No idea why its there, but here's how to disable it with the GNU implementation of bc:

echo '6^6^3' | BC_LINE_LENGTH=0 bc

BC_LINE_LENGTH

This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70.

###Update:

I was confused about this question, I thought it was about the origins of the multi-line feature, it does seem like an odd one. Anyway the real answer is that if you do not quote the variable, the shell will do word splitting on it before this is passed to echo. Word splitting is the process where an expansion is split into 'words' depending on the contents of IFS, these 'words' then become different arguments. In the question example, this creates two arguments to echo, which echo then separates with a space (I knew this before Stephane commented, honest...).

No idea why its there, but here's how to disable it with the GNU implementation of bc:

echo '6^6^3' | BC_LINE_LENGTH=0 bc

BC_LINE_LENGTH

This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70.

###Update:

I was confused about this question, I thought it was about the origins of the multi-line feature, it does seem like an odd one. Anyway the real answer is that if you do not quote the variable, the shell will do word splitting on it before this is passed to echo. Word splitting is the process where an expansion is split into 'words' depending on the contents of IFS, these 'words' then become different arguments. In the question example, this creates two arguments to echo, which echo then separates with a space (I knew this before Stephane commented, honest...).

To prevent this happening, just double quote the variable:

num=$(echo '6^6^3' | bc)
echo "$num"

Sometimes this is actually useful as a way to remove IFS characters from a variable (although printf %s is safer for arbitrary strings). Eg (in bash):

$ var=$'spaces:    newlines:\n\n\ntabs:\t\t\t end'

$ echo "$var"
spaces:    newlines:


tabs:            end
$ newvar="$(printf '%s ' $var)"
$ echo "$newvar"
spaces: newlines: tabs: end
added 415 characters in body
Source Link
Graeme
  • 34.6k
  • 9
  • 90
  • 110

No idea why its there, but here's how to disable it with the GNU implementation of bc:

echo '6^6^3' | BC_LINE_LENGTH=0 bc

BC_LINE_LENGTH

This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70.

###Update:

I was confused about this question, I thought it was about the origins of the multi-line feature, it does seem like an odd one. Anyway the real answer is that if you do not quote the variable, the shell will do word splitting on it before this is passed to echo. Word splitting is the process where an expansion is split into 'words' depending on the contents of IFS, these 'words' then become different arguments. In the question example, this creates two arguments to echo, which echo then separates with a space (I knew this before Stephane commented, honest...).

No idea why its there, but here's how to disable it with the GNU implementation of bc:

echo '6^6^3' | BC_LINE_LENGTH=0 bc

BC_LINE_LENGTH

This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70.

No idea why its there, but here's how to disable it with the GNU implementation of bc:

echo '6^6^3' | BC_LINE_LENGTH=0 bc

BC_LINE_LENGTH

This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70.

###Update:

I was confused about this question, I thought it was about the origins of the multi-line feature, it does seem like an odd one. Anyway the real answer is that if you do not quote the variable, the shell will do word splitting on it before this is passed to echo. Word splitting is the process where an expansion is split into 'words' depending on the contents of IFS, these 'words' then become different arguments. In the question example, this creates two arguments to echo, which echo then separates with a space (I knew this before Stephane commented, honest...).

BC_LINE_LENGTH is GNU-only. You need quotes around ^ in the Bourne shell and zsh -o extendedglob
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

No idea why its there, but here's how to disable it with the GNU implementation of bc:

echo 6^6^3'6^6^3' | BC_LINE_LENGTH=0 bc | cat -A

BC_LINE_LENGTH

This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70.

No idea why its there, but here's how to disable it:

echo 6^6^3 | BC_LINE_LENGTH=0 bc | cat -A

BC_LINE_LENGTH

This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70.

No idea why its there, but here's how to disable it with the GNU implementation of bc:

echo '6^6^3' | BC_LINE_LENGTH=0 bc

BC_LINE_LENGTH

This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70.

Source Link
Graeme
  • 34.6k
  • 9
  • 90
  • 110
Loading