翻阅古今
在要在两种平台(Windows(即cygwin)和Linux)上运行的脚本中使用类路径时,路径也很重要。当我这样做时,我为类路径包括了一个类似这样的函数。带有'-w'选项的'cygpath'命令将路径转换为Windows样式的路径。因此,在此示例中,“ / home / user / lib / this.jar”将被转换为“ C:\ Cygwin \ home \ user \ lib \ this.jar”#!/bin/bashfunction add_java_classpath() { local LOCAL1=$1 if [ "$OSTYPE" == cygwin ]; then LOCAL1="$(cygpath -C ANSI -w $LOCAL1)" fi if [ -z "$JAVA_CLASSPATH" ]; then JAVA_CLASSPATH="$LOCAL1" elif [ "$OSTYPE" != cygwin ]; then JAVA_CLASSPATH="${JAVA_CLASSPATH}:$LOCAL1" else JAVA_CLASSPATH="${JAVA_CLASSPATH};$LOCAL1" fi }add_java_classpath /home/user/lib/this.jaradd_java_classpath /usr/local/lib/that/that.jarjava -cp "${JAVA_CLASSPATH}" package.Main $@