Terminal shows > after entering \

When I press backslash \, I’m given a > (greater than) symbol. What does this mean?


Solution 1:

Whenever you use the command line, there might be an instance when you need to run a command that is very long. So, you want to split the command into multiple lines for better readability and understanding. But if you use new line character which is typed by Enter, the shell will think that it is a new command. So you use \ followed by the newline character.

Basically, commands or bash scripts are "interpreted", i.e. executed line by line. Every new line means the start of a new command. In the terminal, when you press Enter, you get a prompt to run a new command. So, a new line needs to be "escaped". Typing \ followed by Enter allows you to split the current command into multiple lines so the shell doesn't think that it is a new command but the continuation of the previous command.

> is nothing but a prompt for the next line of the command being entered.

For example:
If we want to install multiple packages, the command will be like

$ sudo apt install [package1] [package2] [package3] ...

But sometimes, that makes the command cluttered. So we can use \ followed by Enter (newline character)

$ sudo apt install [package1]\
> [package2]\
> [package3]\
> ...

Solution 2:

The backslash character (\) is used as an escape character in the shell. If you use it as the last character on the line, it escapes the newline, so you can continue your command on the next line instead of finishing it. This is indicated by the > prompt in Bash.

Example:

$ echo A\
> B
AB
$

To put a literal \ to your command, you have to escape it using another backslash:

$ echo \\
\
$