How do you add a new line in the terminal?

I notice sometimes people post a compounded multiple line command to be copied and pasted into the other party’s terminal.
Since return executes commands, how do you get all those instructions in the terminal in multiple lines when you’re typing it out for the first time?

copy and paste line by line

You can also combine commands by way of a semicolon (;), as in the example below… :arrow_down:

ls -l ; echo This is a line of text ; whoami

You can also use a double ampersand (&&) for separating the commands, although its logical meaning to the system is different. A double ampersand signifies a logical AND, and therefore it will only execute the next command if the previous command in the line was successful.

Also, if you want to split up a long command over multiple lines in a script ─ for instance, so as to stay within the recommended 72-character width of the script for readability on text-only terminals ─ then you can add a backslash (\) as an escape character at the end of each line.

Lastly, if you type a long command that contains a loop, a condition, or some other iteration, and you accidentally press Enter/Return before finishing up the command, then the shell will prompt you for the remainder of the command ─ e.g. you forgot to add a done after a for loop ─ with the $PS2 prompt, which by default in Bash is set to >.


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.