Home > OS >  command not found - when every param on new line
command not found - when every param on new line

Time:06-02

In bash file myBuildAndJacoco.sh:

mvn -Pcommon,coverage 
clean 
org.jacoco:jacoco-maven-plugin:prepare-agent 
install 
-Dmaven.test.failure.ignore=true
-Dclient.version=0.2-SNAPSHOT 
-Djacoco.outputDir=${WORKSPACE}/target 

But when I run it I get error:

./myBuildAndJacoco.sh: line 12: clean: command not found
./myBuildAndJacoco.sh: line 14: org.jacoco:jacoco-maven-plugin:prepare-agent: command not found
./myBuildAndJacoco.sh: line 15: -Dmaven.test.failure.ignore=true: command not found
./myBuildAndJacoco.sh: line 16: -Dclient.version=0.2-SNAPSHOT: command not found
./myBuildAndJacoco.sh: line 17: -Dngnms.version=-SNAPSHOT: command not found
./myBuildAndJacoco.sh: line 18: -Djacoco.outputDir=/target: No such file or directory

I need to split all this params to new line.

CodePudding user response:

A bash script run thinks of everything written on a new line as a part of a new command.

for example when running this code

mvn -Pcommon,coverage 
clean

it thinks of mvn ... as one command and clean as another. To prevent it you can use a \ and the end of each line. For example

mvn -Pcommon,coverage \
clean

similarly your entire code should be

mvn -Pcommon,coverage \
clean \
org.jacoco:jacoco-maven-plugin:prepare-agent \
install \
-Dmaven.test.failure.ignore=true \
-Dclient.version=0.2-SNAPSHOT \
-Djacoco.outputDir=${WORKSPACE}/target
  • Related