From time to time I like to use cat >/etc/configfile <<EOF thing, and paste content, then send EOF that will flush it into file. Its good with one or two lines, but when there's more of them, some of content is missing, some extra newlines are added and so one. Same goes if I use patch <<EOF, even with a simple patch with less than 2000 characters in total.

I suspect my terminal (urxvt) to do something wrong, It paste the content extreme fast but miss something, when I use mintty from cygwin, its slow as hell but not a single line is skipped. Also, if I enter Vim and paste it there, nothing is missed. The shell does not matter, happens on zsh, bash and ash.

  • It's called a here doc. tldp.org/LDP/abs/html/here-docs.html – slm Jul 13 '13 at 18:35
  • 3
    Possibly the pasted text contains backticks or dollars. Use <<\EOF – Stéphane Chazelas Jul 13 '13 at 19:21
  • A simpler way to do this is to cat >/etc/configfile, then paste, then hit CTRL+D to finish. That way the shell doesn't get involved. – Jander Jul 14 '13 at 5:48

I can't reproduce the behavior you describe. Your terminal emulator may have a limit on the size of paste buffers, but repeated newlines, if you really have them, sounds like a bug.

Are you sure that you're taking the shell processing into account? In a here document delimited with <<EOF, the characters $ and ` are interpreted by the shell as the start of a variable substitution or command substitution. So for example, if your selection contains

more=$stuff stuff

then pasting it followed by EOF results in a file containing something like

more= stuff

To avoid these substitutions, tell the shell to interpret the here document content literally by quoting the here document marker (cat <<'EOF' or cat <<\EOF or cat <<"EOF" or any other variation).

Make sure that you're pasting the selection you intend. X11 has multiple selections; old-fashioned X11 applications where copying is automatic upon selection use the PRIMARY selection, whereas new-style X11 applications with a separate copy command use the CLIPBOARD selection.

The solution to your problem is not to paste, but to use a program such as xclip or xsel to copy the selection to a file. For the PRIMARY selection:

xclip -o >/etc/configfile
xclip -o | patch
xsel >/etc/configfile
xsel | patch

For the CLIPBOARD selection, call xclip -selection clipboard or to xsel -b.

  • There's no special char, like 300 lines of up ip addr add XXX/YY dev bond0 and after something like 200 it starts dropping, adding enters etc. I will try without <<EOF to check whatever that helps and reports back. – its_not_fun_to_be_devops Jul 14 '13 at 8:58

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.