Apologies if this question is answered somewhere. If so, I will be more than happy to remove or edit this question. But I have searched long and hard for an answer to this (using Google since symbols don't work in StackExchange's search) but have been unable to find anything.
When searching for a command to sum numbers I stumbled upon this StackExchange answer that said the solution laid in a set of piped commands like the following:
<cmd> | paste -sd+ | bc
This seems to be correct, however, as a newer user to Bash scripting I have never seen the paste
command be used with the options -sd+
before. The -s
makes sense as the serial command, but everywhere I look says that the -d
(delimiter) option must be used with a string after it to indicate the string that will be used as the delimiter. (e.g. something like -d "|"
.) Even the manual seems to indicate this:
Mandatory arguments to long options are mandatory for short options too.
-d, --delimiters=LIST reuse characters from LIST instead of TABs
-s, --serial paste one file at a time instead of in parallel
-z, --zero-terminated line delimiter is NUL, not newline
--help display this help and exit
--version output version information and exit
However, the command from the answer listed above does not have a string after it. Instead, it just has a +
symbol (which I assume is for the arithmetic calculation in bc
) and whitespace. And based on the context of the answer, the +
symbol does not seem to be the new delimiter (espcially considering there is no space between it and d
). What is the benefit of having -d
attached if there is no delimiter specified?
So could someone please break down for me what the paste -sd+
command does? Thank you!