Rob Laverty Rob Laverty - 3 months ago 11
Bash Question

Placing bash/shell command flags on a new line


TLDR



How do you put command flags on a new line in a
shell
script?




I'm writing a simple
shell
script that runs a Java
jar
file with a few parameter flags.

Here's what it looks like:

rm -rf ./out &&
sleep 1 &&
java -jar dts-generator.jar -generate-multiple -input android17.jar -input dbflow-core-3.1.1.jar


I want to be able to put these flags on a new line for organizational purposes, like so:

rm -rf ./out &&
sleep 1 &&
java -jar dts-generator.jar
-generate-multiple
-input android17.jar -input dbflow-core-3.1.1.jar


Is this possible to do in Shell Scripting?

Answer

Like this:

java -jar dts-generator.jar \
    -generate-multiple \
    -input android17.jar -input dbflow-core-3.1.1.jar

Note the backslash must be the last character of the line. (It is effectively "escaping" the end-of-line.)

The indentation of the following line is purely cosmetic ... but it makes the script more readable (IMO).

Comments