Most active commenters

    ←back to thread

    217 points tanelpoder | 11 comments | | HN request time: 1.374s | source | bottom
    Show context
    jandrese ◴[] No.26492618[source]
    This seems to be more of "don't paste garbage into a terminal, especially as root." With a sidenote that it might be safer if your custom application command interpreter didn't use > as the prompt character. I note that Bourne shell defaults to the safer % and # characters for the prompt. The # character for root is especially safe.
    replies(6): >>26492739 #>>26492951 #>>26494723 #>>26499063 #>>26499191 #>>26501459 #
    1. tanelpoder ◴[] No.26492951[source]
    Yep (author here), not pasting garbage into a terminal is the main point of this article. Partially, it's a rant against the way-too-trigger-happy "paste clipboard on right mouse click" terminals too.

    I decided to finally write this article, after seeing a yet another "mysterious" case of a missing binary in some Oracle database server. Linux/Bash defaults are ok, but historically (coming from traditional Unix background?), people who engineer environments at least in the Oracle database server world, configure their prompts to some "corporate standard". And sometimes they end up suffixing prompts by a nice-looking ">" character, leading to this problem.

    I've also seen someone set their root prompt to `root#>`. Since there's no space between the username and #, the "comment start" is not recognized and the redirection clobbering problem is still there.

    replies(2): >>26493955 #>>26495384 #
    2. tener ◴[] No.26493955[source]
    Well, how about making it hard to do accidental input in the first place? If pasting is a problem the maybe make the actions necessary less possible to be triggered randomly?
    3. adrian_b ◴[] No.26495384[source]
    Because of this problem, good terminals require confirmation before pasting any strings that contain suspicious characters, e.g. carriage returns.
    replies(1): >>26498491 #
    4. tinus_hn ◴[] No.26498491[source]
    I have seen a ‘good terminal’, apparently. Can you name one?
    replies(3): >>26498639 #>>26499237 #>>26517765 #
    5. JdeBP ◴[] No.26498639{3}[source]
    Two examples: PuTTY and Windows Terminal both present confirmation dialogue boxes before pasting multiline content.
    replies(2): >>26499034 #>>26500498 #
    6. bombcar ◴[] No.26499034{4}[source]
    iTerm seems to do this also at least with multi line pastes - and then zsh seems to wait for you to hit enter AGAIN before executing anything.
    replies(1): >>26499201 #
    7. CGamesPlay ◴[] No.26499201{5}[source]
    In iTerm, Edit -> Paste Special -> Warn Before Multi-Line Paste will disable it if you don't like it. It's probably better to disable it in zsh, but I don't know how to do that. iTerm also provides the "only pop up this warning when I'm at a shell prompt", which is ironically exactly when I don't want it to pop up (since zsh/fish detect it themselves).
    replies(1): >>26500393 #
    8. klyrs ◴[] No.26499237{3}[source]
    I was musing over IPython's behavior right before reading your comment... it's not a terminal, per se, but if you paste in multiple lines, the input switches into a multiline mode. This suggests that bash could handle it in the same manner without relying on a terminal application.

    In my experience, the advice "don't paste garbage into your terminal" is about as useful as "don't make mistakes." Sometimes it happens when I forget to hit shift on copying from a terminal, or accidentally holding it while copying from another window. Humans make mistakes. I like seatbelts even though they've never saved my life.

    9. JNRowe ◴[] No.26500393{6}[source]
    Using "unset zle_bracketed_paste" should do what you want, but I've only tried it in rxvt-unicode and the vte-based term I have. It stops zsh reacting to the escape sequences used by multi-line paste, see the docs for a full explanation¹.

    If you were to use I'd recommend sticking it behind a "if $TERM" guard so that it you don't end up surprised if you switch to a term that doesn't warn at some point ;)

    ¹ http://zsh.sourceforge.net/Doc/Release/Parameters.html#index...

    10. GoblinSlayer ◴[] No.26500498{4}[source]
    PuTTY accepts multiline pastes for me just fine, I use it with nano.
    11. andrey_utkin ◴[] No.26517765{3}[source]
    Xfce4-terminal prompts for confirmation when there's newline in the pasted contents.