1

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'"

or

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.

cipricus
  • 1,529

1 Answers1

2

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'
Stephen Kitt
  • 434,908