Search code examples
windowsbashcygwinfilenamesslash

cygwin bash forward slash converted to backslash


Cannot figure this one our or create a sample which can reproduce this.

Am trying using an external sh file to invoke the hadoop sh file

myfile.sh

# workingdir = /data1/some/path/lib
WORKINGDIR=`cygpath -p -w -m "$WORKINGDIR"`
# so the above in windows land is C:/some/path/lib
# HADOOPCMD essentially is a call to hadoop.sh
$HADOOPCMD jar $WORKINGDIR/myjar.jar

hadoop.sh

echo "$@" // still C:/some/path/lib
exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"

However when "$@" is expanded in cygwin the resultant path becomes C:\some\path\lib and then the hadoop.sh complaints that it cannot find the jar ... Not a valid JAR : C:\some\path\lib

However if I were to hardcode the path in myfile.sh ; it works

$HADOOPCMD jar C:/some/path/lib/myjar.jar

Question

  1. why does the exec command's "$@" change the / to \ in the WORKINGDIR variable ?
  2. why does the hardcoded path work ?
  3. how to get this to work with variable substituion ?

Solution

  • Quoting the variable works "$WORKINGDIR"/myjar.jar