@@ -146,10 +146,41 @@ if $cygwin; then
146146fi
147147export CLASSPATH
148148
149+ # Properly escape java options, dealing with whitespace, double quotes and backslashes
150+ # This accepts a string, and returns the escaped list through ESCAPED_JAVA_OPTS
151+ escape_java_options () {
152+ ESCAPED_JAVA_OPTS=() # return value
153+ option_buffer=" " # buffer for collecting parts of an option
154+ opened_quotes=0 # whether we are expecting a closing double quotes
155+ for word in $1 ; do
156+ contains_quote=$( echo " $word " | grep \" | grep -v \\\\\" )
157+ if [ -n " $contains_quote " ]; then
158+ # Flip the bit
159+ opened_quotes=$(( (opened_quotes + 1 ) % 2 ))
160+ fi
161+ if [[ $opened_quotes == 0 ]]; then
162+ ESCAPED_JAVA_OPTS+=(" $( echo " $option_buffer $word " | sed " s/^[[:space:]]*//" | sed " s/\([^\\ ]\)\" /\1/g" ) " )
163+ option_buffer=" "
164+ else
165+ option_buffer=" $option_buffer $word "
166+ fi
167+ done
168+ # Something is wrong if we ended with open double quotes
169+ if [[ $opened_quotes == 1 ]]; then
170+ echo " Java options parse error! Expecting closing double quotes." 1>&2
171+ exit 1
172+ fi
173+ }
174+
175+ escape_java_options " $JAVA_OPTS "
176+ for option in " ${ESCAPED_JAVA_OPTS[@]} " ; do
177+ echo " $option "
178+ done
179+
149180if [ " $SPARK_PRINT_LAUNCH_COMMAND " == " 1" ]; then
150181 echo -n " Spark Command: " 1>&2
151- echo " $RUNNER " -cp " $CLASSPATH " $JAVA_OPTS " $@ " 1>&2
182+ echo " $RUNNER " -cp " $CLASSPATH " " ${ESCAPED_JAVA_OPTS[@]} " " $@ " 1>&2
152183 echo -e " ========================================\n" 1>&2
153184fi
154185
155- exec " $RUNNER " -cp " $CLASSPATH " $JAVA_OPTS " $@ "
186+ exec " $RUNNER " -cp " $CLASSPATH " " ${ESCAPED_JAVA_OPTS[@]} " " $@ "
0 commit comments