1

I have a command to execute in a bash script. If I run the command directly in the console, it works fine but if I put it in a script and execute the script, it throws the following error:

Bad command-line arguments

The command I successfully executed in the console is:

output=`java -jar myjar.jar -agent iOS -host localhost /Users/vskumar/monkeytalk/workspace/MonkeyProject/'shoppingcart_deleteproduct - Online_V2.mt'`

In the script, it looks like this:

output=`java -jar $JAR_LOCATION/$JAR_LIST -agent $AGENT_NAME -host $HOST -reportdir $REPORT_DIR/$rep_date $MT_TEST_ROOT_DIR/$SUBSTRING`

where the value of $MT_TEST_ROOT_DIR is

/Users/vskumar/monkeytalk/workspace/MonkeyProject

and the value of $SUSBSTRING is

'shoppingcart_deleteproduct - Online_V2.mt'
1
  • 2
    Quote your variables. Commented Feb 27, 2016 at 2:09

1 Answer 1

4

Note that you have spaces in the $SUSBSTRING variable that are interpreted as multiple parameters. In order to fix that just put double quotes around your variables:

 output=`java -jar "$JAR_LOCATION"/"$JAR_LIST" -agent "$AGENT_NAME" -host "$HOST" -reportdir "$REPORT_DIR"/"$rep_date" "$MT_TEST_ROOT_DIR"/"$SUBSTRING"`
Sign up to request clarification or add additional context in comments.

2 Comments

even for those that don't have spaces?
It is good practice to quote all your variables, you never know when the spaces will strike...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.