Search code examples
bashsingle-quotes

Single Quote Entry in Bash


I accidentally entered a single single quote in the commandline of my Debian x86_64 laptop. This starts a > prompt. A second single quote ends the prompt, with the message that the command could not be found.

What is happening here? What commands (if any) are expected?


Solution

  • You can add quotes around values to ensure they're treated as strings and not interpreted, e.g.:

    $ echo 'Hello > foo.txt'
    Hello > foo.txt
    

    Note that without quotes this would have been a very different command.

    Strings can also include newlines:

    $ echo 'Hello
    > World'
    Hello
    World
    

    That's all you're seeing there, a line continuation.

    $ '
    > '
    command not found: \n
    

    This simply means you entered a newline character as the one and only thing, so it's being interpreted as a command (e.g. like echo), and it's not a defined command.