8

I got a shell script and inside I got the command as below

#!/bin/sh
sh ../jboss/bin/standalone.sh --server-config=standalone-full.xml -Djboss.node.name=node1 -b 0.0.0.0 -bmanagement 0.0.0.0

How can I break the line to multiple lines for better understanding and management

#!/bin/sh
sh ../jboss/bin/standalone.sh 
  --server-config=standalone-full.xml
  -Djboss.node.name=node1
  -b 0.0.0.0
  -bmanagement 0.0.0.0

Tried with backslash at the end of each line and it doesnt work.

0

2 Answers 2

12

This is known as continuation, and uses \ as the very last character on each line apart from the last one:

#!/bin/sh
sh ../jboss/bin/standalone.sh         \
  --server-config=standalone-full.xml \
  -Djboss.node.name=node1             \
  -b 0.0.0.0                          \
  -bmanagement 0.0.0.0

(aligned for cosmetic purposes, they don’t have to be).

For more on this, see Shell Syntax: How to correctly use \ to break lines? and the linked questions.

1
  • 1
    \ as the very last character on each line this is very important, avoid space chars after the \
    – nulll
    Commented May 5, 2023 at 8:54
8

Working on the idea from Paul_Pedant's comment, in Bash/ksh/zsh you could use an array:

#!/bin/bash
args=(
  --server-config=standalone-full.xml
  -Djboss.node.name=node1
  -b 0.0.0.0
  -bmanagement 0.0.0.0
)
sh ../jboss/bin/standalone.sh "${args[@]}"

Here, the parenthesis provide the syntactic clue the shell needs to know when the array assignment ends. Sadly, this only works with an array assignment, not with just the single command.

Also, if the jboss script is properly set with execute permissions and a hashbang in the script, you should be able to run it as just ../standalone.sh, without the explicit sh in front.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .