I want to copy a file to clipboard and then execute it as we do with "ctrl+shift+v", but the copy and paste on line command.

In my case I can't just run a .sh. I have to copy and paste.

I want to connect to ssh and run a command. When I use paste, it works.

I want to see what is going on the terminal, not just send a script to run.

No keyboard keys, just command line.

  • Your question is quite unclear, even with the recent edit. Do you want to connect from a command line on one machine with no GUI, to the cli on another machine via ssh, and run a series of commands? Are these commands already in a file? – Arronical Sep 15 '16 at 10:45

I am not sure whether I understand what you are trying to achieve, but you can easily run long commands or scripts without storing them as a file by using Bash's command editor.

Press Ctrl+X, then Ctrl+E. This will bring up your default editor, usually nano.

In here you can now easily paste the commands or the full script you want to run.

When you're finished, exit nano saving the changes by pressing Ctrl+X ("Exit"), then answer Y (or whatever letter represents "Yes" in your locale) when asked whether to "Save modified buffer". Then press Enter to accept the proposed temporary file name.

As soon as the editor terminates, Bash will run the temporary script and then delete it afterwards.


The easiest way would be to send file straight to "sh" without using the clipboard:

sh < file.sh

Or alternatively, to run the file without spawning a new process:

`cat file.sh`

If you really need to use the clipboard, refer to A command-line clipboard copy and paste utility?

  • What I want to run is on a file. But it should execute like pasting. I cant ./file.sh it doesn't work for my purpose. – Vitor Abella Sep 15 '16 at 9:40
  • Does the file contain shell commands, like a regular .sh file? In that case my second example should work like pasting into the console. If not, please explain what difference the pasting does in your situation. – Janek Sep 15 '16 at 9:43
  • I will try it right know – Vitor Abella Sep 15 '16 at 9:44
  • I don't think `cat file` will work. backticks are meant as a process substitution for another command , you would need to use something like eval `cat file.sh` – the_velour_fog Sep 15 '16 at 9:47
  • It does work, I tried it myself before posting. :) – Janek Sep 15 '16 at 9:49

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.