gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
How to make command continue on next line in bash script ?
- User
How to make command continue on next line in bash script ?
- Assistant
In a Bash script, if you want to continue a command onto the next line, you can use the backslash
\character at the end of the line to indicate that the command continues on the next line.Example:
echo "This is a very long line that I want to \ continue on the next line"This will output:
This is a very long line that I want to continue on the next lineKey points:
- The backslash
\must be the last character on the line (no trailing spaces after it). - This works for commands, variable assignments, loops, conditionals, etc.
Example with a more complex command:
grep "search_pattern" file.txt | \ sort | \ uniq -c | \ sort -nrThis chains the commands over multiple lines for better readability.
Alternatively, many shell constructs implicitly allow multi-line commands if the syntax is incomplete, for example:
if [ "$var" -eq 1 ] && \ [ "$other_var" -eq 2 ]; then echo "Both conditions met" fi - The backslash