shamon shamsudeen
shamon shamsudeen

Reputation: 5848

Bash script execution in Mac os: directory not exists error

I have a command like this

bash -c 'cd \"/Users/Shammon/Projects/t2i-tokenisation-corda/build/nodes/AGCSIT\" ; \"/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/bin/java\" \"-Dcapsule.jvm.args=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5008 -javaagent:drivers/jolokia-jvm-1.6.0-agent.jar=port=7008,logHandlerClass=net.corda.node.JolokiaSlf4jAdapter\" \"-Dname=AGCSIT\" \"-jar\" \"/Users/Shammon/Projects/t2i-tokenisation-corda/build/nodes/AGCSIT/corda.jar\" && exit'

When I run this in match terminal, I am getting the following error

bash: line 0: cd: "/Users/Shammon/Projects/t2i-tokenisation-corda/build/nodes/AGCSIT": No such file or directory bash: "/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/bin/java": No such file or directory

But the paths are valid ones

Upvotes: 0

Views: 253

Answers (1)

Barmar
Barmar

Reputation: 780909

Escaping the double quotes causes the shell to look treat them as literal parts of the filenames and parameters, instead of just it into a single token. There's no need to escape the quotes.

bash -c 'cd "/Users/Shammon/Projects/t2i-tokenisation-corda/build/nodes/AGCSIT" ; "/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/bin/java" "-Dcapsule.jvm.args=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5008 -javaagent:drivers/jolokia-jvm-1.6.0-agent.jar=port=7008,logHandlerClass=net.corda.node.JolokiaSlf4jAdapter" "-Dname=AGCSIT" "-jar" "/Users/Shammon/Projects/t2i-tokenisation-corda/build/nodes/AGCSIT/corda.jar"'

There's also no need for && exit at the end. When the command is done, the shell automatically exits.

Upvotes: 2

Related Questions