3

I want to paste some text into a terminal and save it to a file without using an editor, but just 'cat'.
But too long lines or tabs in text make it impossible to do so with a simple command like "cat >test.txt" or "cat <<'EOF' >test.txt" ("here document").

In bash in "here document" mode if pasted text data contains tabs, they cause autocomplete.
If I start bash with '--noediting', on some systems the length of pasted line is limited to 256 chars, the rest of pasted text is discarded.
If instead I paste directly to cat's input (without <<'EOF'), the max line is also 256.

If I do:

stty raw; cat >test.txt; stty sane

, the line length is no longer limited, but there's no way to send EOF to cat's input.
If I enable eof char:

stty raw icanon eof '^d'; cat >test.txt; stty sane

long lines are lost.

Also, if I don't disable echo with:

stty -echo

, the combination of Solaris 10 and Putty cause large blocks of text ~1500chars to be lost, sometimes resulting an empty file.

The closest I got to what I want is to kill cat with timeout:

( sleep 15; pkill cat ) & stty raw -echo; cat >test.txt; stty sane; echo done

or to use bash --noediting with raw:

bash --noediting
stty raw -echo icrnl
cat <<'EOF' >test.txt; stty sane
6
  • 3
    Can you please say your question more clearly and what are you going to do? Commented Aug 28, 2013 at 6:53
  • 1
    Please don't downvote. If you don't understand the question, it means you're not a specialist. Your negative vote repels people who could answer.
    – basin
    Commented Aug 28, 2013 at 9:22
  • I don't downvote you can see my reputation, BUT please say your question clearly and edit your post, Thanks Commented Aug 28, 2013 at 9:25
  • 1
    I am still not sure what you are trying to do. I would guess you are trying to paste from your X clipboard into a file without opening an editor. Also I am not sure if you are looking for a scriptable or interactive solution. Such unclear things are probably the the reason for your downvotes. Googling what I think is your question brought me to this question. Maybe xclip -o > test.txt does the trick for you.
    – Tim
    Commented Aug 28, 2013 at 13:48
  • @Tim I'm connecting to Solaris with Putty from a Windows session on a Citrix XenApp server, to which I'm connecting from Windows 7 with a XenApp client. I can't copy files, all I have is clipboard.
    – basin
    Commented Aug 28, 2013 at 18:28

1 Answer 1

1

If you're using bash, you can disable tab-completion before you paste then reenable it afterwards by using the bind command:

bind '\C-i:self-insert'
# paste away
bind '\C-i:complete'

This is unwieldy, but it works.

When manually typing on the bash command-line you can enter a literal tab by first pressing CTRL-V then tab. Obviously you can't do this when pasting and I was annoyed enough by this that I patched my favorite terminal program iTerm2 with a "Paste Special" command that sends literal tabs via a CTRL-V,tab sequence.

I only tonight wrote and submitted this patch, so if you want a version of iTerm2 that does this you'll have to compile your own from my fork at GitHub using Xcode. Hopefully it will get merged into the main application, if it does I'll update this answer. EDIT: The changes I made are now in the main branch of iTerm2. Use the Edit -> Paste with Literal Tabs command.

If you're using a different OS or terminal program sorry, I can't help with that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .