3
1
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
3Can you please say your question more clearly and what are you going to do? – Sepahrad Salour – 2013-08-28T06:53:42.243
1Please 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 – 2013-08-28T09:22:45.097
I don't downvote you can see my reputation, BUT please say your question clearly and edit your post, Thanks – Sepahrad Salour – 2013-08-28T09:25:40.097
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
– Tim – 2013-08-28T13:48:59.923xclip -o > test.txt
does the trick for you.@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 – 2013-08-28T18:28:35.923
I could not see this from your question. Maybe you should clarify it. So if you want to transfer a file (or if this would help you), can't you just copy it first to your XenApp session (should be possible somehow) and from there using scp? – Tim – 2013-08-29T07:42:45.753