3

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
7

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.

0
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.