This is very basic, sorry if this is a duplicate, but search results give me something opposite.

I want to paste lines as an input to a pipe. How can I do it?

For example I want to use this answer https://stackoverflow.com/a/18141152/2361465 to sum a line of numbers. I could save my numbers into a file and do

cat numbers.txt | paste -sd+ - | bc

But my numbers are in the clipboard. Or they are in my head and I want to enter them manually. How do I feed them as the input without saving to a file?

I don't want the shell to read the Ubuntu clipboard, I want some command ??? that after execution waits for the input (with some way of indicating its end) and then passes it to the pipe.

??? | paste -sd+ - | bc

1 Answer 1


You don't need anything else - just type

paste -sd+ | bc

then hit ENTER after which you can type or paste the numbers (separated by newlines), ending your input with CTRL+D

$ paste -sd+ | bc

Alternatively, use a here document

$ paste -sd+ <<EOF | bc
> 1.23
> 4.56
> 7.89
  • More generally, you can use cat <<EOF | ... and then type the input and end it with EOF on it's own line (EOF is by convention, could be any other string).
    – Tgr
    Feb 8, 2020 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.