1

I have a linux command:

sudo su - -c "echo 'exit 1'> /usr/lib/ocf/resource.d/oom_check_ocf.bsh"

I want to create this command and store it into a string.

The end portion of the string will be a variable healthScript, such as

healthScript= /usr/lib/ocf/resource.d/oom_check_ocf.bsh

What I have tried:

"sudo su - -c"+" "echo 'exit 1' > +healthScript""

I am confused because the linux command has double quotes in it, which are used to wrap the executed command, which is:

echo 'exit 1'> /usr/lib/ocf/resource.d/oom_check_ocf.bsh

How do I write a string which has double quotes inside?

jrtapsell
  • 6,719
  • 1
  • 26
  • 49
DevRight
  • 345
  • 1
  • 6
  • 25

1 Answers1

1

you need to escape ""

String healthScript="sudo su - -c \""+"echo 'exit 1'> /usr/lib/ocf/resource.d/oom_check_ocf.bsh\"";
    System.out.println(healthScript);

output:sudo su - -c "echo 'exit 1'> /usr/lib/ocf/resource.d/oom_check_ocf.bsh"

SpringLearner
  • 13,738
  • 20
  • 78
  • 116