This is somehow a follow-up to my last question: Pasting multiple commands into terminal stops at user input

Pasting the following to the terminal works as expected:

echo test1
# some comment
echo test2

But pressing arrow up to repeat that command gives the following obviously wrong command:

( echo test1 echo test2; )

Pasting the same without the comment and pressing arrow up gives the expected command:

(echo test1; echo test2)

An easy workaround is to add ; before each line with a comment.

But why is this the case ? Is it a bug ?

I use bash. Same behavior in gnome-terminal and tilix.

  • 2
    As I commented on your previous question, don't past shell code inte the terminal. If you have a workflow that depends on you pasting shell code into a terminal, then you really seriously have to reconsider that workflow. – Kusalananda Jul 20 '18 at 9:42
  • Please edit your question and tell us what shell you are using and what terminal emulator. – terdon Jul 20 '18 at 9:46
  • Using bracketed paste as suggested in JoL's answer handles this better. – muru Jul 20 '18 at 9:46
  • This depends on the shell you are using. Using e.g. zsh will work as expected. – Anderson Jul 20 '18 at 9:47
  • 3
    @Kusalananda that doesn't change the fact that this is an interesting behavior though. Why would the comments change things? And we often paste a few lines of code into a terminal, that isn't always a bad thing. – terdon Jul 20 '18 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.