I am trying to answer this other question: Command/script to start a terminal, enter text but don't execute.... I want to start the terminal and add specific text to it without executing, thus allowing me to copy some other variable text to it before executing. It's like when pasting sudo apt install mpv into terminal without space at the end: the command will not start, but allow for example to add other programs to be installed.

I have come close to a solution with xsel, which can send a command to terminal with a shortcut.

The commands to be used can be something like

bash -c "xsel -ib <<< 'MY_TEXT'"


bash -c "xsel -p <<< 'MY_TEXT'"

Thus, I can send that text to clipboard with one shortcut, open terminal with another shortcut, then paste what xsel has copied to clipboard.

The problem is that the xsel command sends to clipboard the text with a space or Enter at the end

enter image description here

It's MY_TEXT instead of MY_TEXT

It's like the difference between sudo apt install mpv which automatically runs the installation command and sudo apt install mpv that waits for me to press enter.


Here strings have a newline appended to them. If you avoid that, you won’t get a newline in the pasted text:

bash -c 'printf "%s" "MY_TEXT" | xsel -p'
  • I hope I'm not out of line here: could you tell me also if there's a possible answer to my linked question? Trying with printf '%s' "MY_COMMAND" | xsel -p && konsole --hold -e xsel -p to get MY_COMMAND in terminal and wait for new input (like when pasting sudo apt install mpv), I get MY_COMMAND \ No newline at end of selection: I would like to get just MY_COMMAND and be able to type/paste a path after that.
    – cipricus
    Apr 8 at 15:51
  • I don’t know (otherwise I’d answer your other question directly). Apr 8 at 16:12
  • 1
    Meanwhile, you provided me with a 3-step workaround: here.
    – cipricus
    Apr 8 at 16:42
  • Made that 2-step :)
    – cipricus
    Apr 8 at 17:20

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.