Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > Paste in Terminal: Avoid Line Breaks?

Paste in Terminal: Avoid Line Breaks?
Thread Tools
tavilach
Mac Elite
Join Date: Jan 2004
Location: Berkeley, CA
Status: Offline
Reply With Quote
Nov 10, 2006, 05:30 AM
 
I'm having trouble copying and pasting from TextEdit into the Terminal. When my text has line breaks, Terminal sends the command after each line break, instead of copying the whole chunk of text and waiting for me to press enter. What setting can I change, or what button can I press, to avoid this?
"Give me a lever long enough and a fulcrum on which to place it, and I shall move the world." -Archimedes
     
Simon
Posting Junkie
Join Date: Nov 2000
Location: in front of my Mac
Status: Offline
Reply With Quote
Nov 10, 2006, 05:33 AM
 
Insert a \ before every line break.
     
tavilach  (op)
Mac Elite
Join Date: Jan 2004
Location: Berkeley, CA
Status: Offline
Reply With Quote
Nov 10, 2006, 06:26 AM
 
That defeats the whole purpose of copy/pasting, doesn't it? Anything more automatic?
"Give me a lever long enough and a fulcrum on which to place it, and I shall move the world." -Archimedes
     
chrismear
Fresh-Faced Recruit
Join Date: Jan 2002
Location: London
Status: Offline
Reply With Quote
Nov 10, 2006, 11:12 AM
 
Well, there's Edit > Paste Escaped Text, which will escape the carriage returns for you. But it will also escape all special characters, including spaces. So it's likely this won't achieve what you want.

Terminal.app doesn't have an 'only escape carriage returns' option, unfortunately.

In TextEdit, you could do a Find to automatically replace all the "CR"s with "\CR". Put your cursor in the "Find" box, and type "Cmd-A Opt-Return" to select everything and replace it with a carriage return. Then put your cursor in the "Replace with" box and type "Cmd-A \ Opt-Return". Once you've added backslashes to the end of each line, you should be able to copy and paste into Terminal as desired.

The problem with Terminal.app is that it's just talking to a standard UNIX terminal, which doesn't natively understand 'text' as an object to be pasted in and out like the rest of OS X does. When you paste text into Terminal.app, it converts it into a string of characters (including carriage returns), and then virtually types it into the terminal as if you'd typed them yourself. This is why pasting even works when you're connected to an esoteric remote terminal. But it means that if you want something escaped when you paste it in, you have to tell it specifically.
     
WJMoore
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Nov 10, 2006, 09:09 PM
 
What about a Service (or widget) that strips new lines? Select the text, choose the service, copy paste? Something like this must exist right?
     
Hal Itosis
Grizzled Veteran
Join Date: Mar 2004
Status: Offline
Reply With Quote
Nov 11, 2006, 07:03 PM
 
Originally Posted by tavilach View Post
I'm having trouble copying and pasting from TextEdit into the Terminal. When my text has line breaks, Terminal sends the command after each line break, instead of copying the whole chunk of text and waiting for me to press enter.
Mine doesn't do that... long lines work fine, both with and without \ line continuation chars.
Perhaps you should tell us your OS version and shell. (I use bash 2.05b.0 under Tiger 10.4.8)

--

Actually, now that I re-read chrismear's post... he's got a point: the shell will react to some chars
in certain ways. It does NOT like ascii $'\015' (not even if you add it the the definition for $IFS).

Another example: if the ~/.bashrc file is used to bind '"\t":menu-complete' then, pasting a bunch
of text that contains any tab chars will produce unpredictable results... as the shell takes the tab
and "completes" it in whatever way works at the moment.

I offer 2 solutions: 1) learn how to write shell scripts, and 2) try TextWrangler. TextWrangler has
a pretty cool feature set... and it allows you to build -- and run -- a script in a "text" document.
( Last edited by Hal Itosis; Nov 11, 2006 at 07:23 PM. )
-HI-
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:00 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,