Sometimes terminal runs commands when pasted, sometimes not.

C

CrazedNerd

Guest
I really love the power of copy/paste...however, i'm a little unsettled by the fact that my gnome-terminal sometimes just runs the commands when I paste them. Does it just do this with certain commands? Is this a known thing that can be changed through configuration?
 


It's how you copy/paste 'em. If you have a character on a new line in the buffer, the terminal reads it as an enter action and runs the command.

Copy the following - all of it, including the blank line:


uptime



(I may need to edit this, I'm not sure if the code above will come through properly with the blank line.)

Yeah, that should work.

Copy "uptime" *and* the blank line under it. Then paste it into your terminal.
 
It's how you copy/paste 'em. If you have a character on a new line in the buffer, the terminal reads it as an enter action and runs the command.

Copy the following - all of it, including the blank line:


uptime



(I may need to edit this, I'm not sure if the code above will come through properly with the blank line.)

Yeah, that should work.

Copy "uptime" *and* the blank line under it. Then paste it into your terminal.
Yeah that works, and just copying the word "uptime" by itself does not cause it to run automatically.

Through google, i've learned that there are 80 characters to a line...so if something gets pasted to the 81st, then the command will run automatically? I'm still a little confused by this...
 
I think it has to be a new line, which is itself a character, and then it has to be blank after that new line. Meaning the following character must be a blank character. So A B has a blank character between them and the B will be ignored/not run.

So...

Code:
uptime
   reboot

It will not run the reboot command - it'll run uptime because of the space and then show reboot without actually rebooting. Actually, let's make sure that doesn't reboot you by accident.

Code:
uptime
   lsb_release -a

There, it should not run the last command - but it will output it on a new line as it's in your copy/paste buffer.

I've never looked into it or read anything about this, I'm just basing it off observations of the behavior.
 
However the terminal assigns the obscure /n...but that's all I really need to know...
 
Code:
for i in {1..100}; do cp test.ogg "test_$i.ogg" ; done

I was asking this in reference to that, and i found through testing that "done" is actually what triggered the automatic running...but interesting to know the whitespace does it too. I was concerned because that was some bash code i copied off line, without changing it just loops an error 100 times...doesn't hurt to just put long commands like this into a separate script file.
 
Through google, i've learned that there are 80 characters to a line...

That is only where a default-sized terminal is used.

Many distros default to 80x24, so the 81st will move to a new line (like word wrap).

Some of mine default at 100x26 so it would be the 101st.

If you go fullscreen with the Terminal, you would likely get 2 to 2.5 times the amount.

Wiz
 
That code doesn't auto-run here when I carefully copy/paste it.
Hmm, well I was entering a little bit of code at a time (started with each word, but then I changed it to each blank space...when it wasn't triggering the auto- run), after each fail to auto-run I used ctrl+u to erase the line...I think in this instance the "done;" triggered it, but it probably just has to do with newline, that smidget is about 59 characters. My confusion deepens...
 
I copied it carefully - doing my copy from right to left. I most always copy/cut that way out of habit for just this reason (and for the paste results in things like text documents, where I don't want a superfluous new line).

As mentioned, I've never really dug into the reasons, I've just observed the behavior and just assume it's the new line (line ending) character being inserted and doing what a new line character is supposed to do.

In some text editors you can opt to show said character. There's also a difference between the new line Unix/Linux uses and the one Microsoft uses. I'm not sure if it's intended, but it probably is, we have a user whose name is @dos2unix - which is an application for converting said line endings.
 
I copied it carefully - doing my copy from right to left. I most always copy/cut that way out of habit for just this reason (and for the paste results in things like text documents, where I don't want a superfluous new line).

As mentioned, I've never really dug into the reasons, I've just observed the behavior and just assume it's the new line (line ending) character being inserted and doing what a new line character is supposed to do.

In some text editors you can opt to show said character. There's also a difference between the new line Unix/Linux uses and the one Microsoft uses. I'm not sure if it's intended, but it probably is, we have a user whose name is @dos2unix - which is an application for converting said line endings.
It has to do with maybe that one extra character of white space, because i just did the same thing and it didn't run either...if i had know this, i would have been free to alter the code and expansion to accomodate the file that i was trying to duplicate...i have very little experience in terms of using bash as standard code, but enough of standard code experience to know how to change it to alter my needs easily.

I'm gonna redirect standard error just to show/test what happens. Here, i copied an pasted what i wrote about, added redirection, hit enter, this winds up in the document:

Code:
for i in {1..100}; do cp test.ogg "test_$i.ogg" ; done 2> duplicate.txt

Code:
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory
cp: cannot stat 'test.ogg': No such file or directory

And next, i've tried selecting the white space from my quote (just one character), it didn't loop, but when i open gedit, it just runs automatically when i do the same thing, so yeah, you're right about the newline character, it doesn't even matter the number of characters but if there's just ONE blank space after what you were trying to do, bash reads it as a newline and it starts the error loop!

some would see this as pretty inane and boring, but to me was worthwhile to learn, cheers.
 
I think the lesson here is to be careful how (and what) one copies and pastes into the terminal. I believe I've written about that before. Something like, "Don't copy/paste directly into the terminal unless you know exactly what the command is going to do."
 
I think the lesson here is to be careful how (and what) one copies and pastes into the terminal. I believe I've written about that before. Something like, "Don't copy/paste directly into the terminal unless you know exactly what the command is going to do."
That's pretty obvious...you don't learn about rm without a warning, however, nobody ever told me that an extra white space character would cause the terminal to execute...the nuance does matter, so many warnings don't.

I only ever deleted files accidentally with thr rm command once, luckily it didn't matter because I backed up my coding templates to the cloud before it happened.
 
Pasting as plaintext won't give you this issue unless you have a trailing CR or LF char. Regular spaces (ASCII code 32) will not trigger this. Bare in mind that most sites use UTF-8 character encoding. This should be true for tour terminal emulator, but may yet, despite that, be set differently. Check the default encoding.
Windows uses CR+LF, for reference. You can avoid this bug completely by typing a \ (space + backslash) first, then pasting whatever behind it.
 
Pasting as plaintext won't give you this issue unless you have a trailing CR or LF char. Regular spaces (ASCII code 32) will not trigger this. Bare in mind that most sites use UTF-8 character encoding. This should be true for tour terminal emulator, but may yet, despite that, be set differently. Check the default encoding.
Windows uses CR+LF, for reference. You can avoid this bug completely by typing a \ (space + backslash) first, then pasting whatever behind it.
I think knowing that extra white space triggers is enough, I've tested it so much that I'm sure that this is what causes it, and thanks to KGIII again for helping me to come to this conclusion.

I still have a glass keyboard that behaves like a smart phone, and I stopped using it because it accidentally triggers things so easily, in terms of stuff getting entered that you didn't ask for...it scared me, that can destroy your system and lose your data! :oops:
 
i'm a little unsettled by the fact that my gnome-terminal sometimes just runs the commands when I paste them.
Do you mean they run automatically without pressing Enter? I use konsole, and from time to time I copy/paste stuff, but I have to hit enter for it to run, I might be confused, but it seems to me commands that run automatically just like that ... IDK ... seems ... inconvenient.
 
Another tip when you copy/paste into a terminal is type out a # first before you paste .. then, after pasting if it looks good, ctrl-a to get to the beginning of the line and delete it.

I'll normally have another terminal open and just paste whatever it is into an empty file first, read through it, then paste in a terminal.
 
Do you mean they run automatically without pressing Enter? I use konsole, and from time to time I copy/paste stuff, but I have to hit enter for it to run, I might be confused, but it seems to me commands that run automatically just like that ... IDK ... seems ... inconvenient.
Yes. We already figured it out, if you have extra whitespace after the command it causes it to do that.
 
Yes. We already figured it out, if you have extra whitespace after the command it causes it to do that.
Ah, ok. So, you were asking how not to or why that happened? I thought you were asking why some commands didn't run automatically, as if that was the behavior you expected; that pasted commands to terminal were executed automatically without you having to hit enter first.
 
Ah, ok. So, you were asking how not to or why that happened? I thought you were asking why some commands didn't run automatically, as if that was the behavior you expected; that pasted commands to terminal were executed automatically without you having to hit enter first.
Yes, it's unsettling if the terminal is doing something annoying w/out my explicit permission. I expect it from my phone because of how they work, but not from my keyboard/mouse controlled desktop!:mad:
 

Staff online


Top