Cygwin 已经提供了一种在 UNIX (POSIX) 风格的路径和 Windows (MS-DOS) 风格的路径之间进行转换的方法,它被称为“ cygpath ”。
尝试:
java -jar `cygpath -w ./foo/bar/file.jar command file.1 file.2`
注意:这些是围绕 cygpath 调用的反引号。
使用 cygpath 无需编写自己的 bash 脚本来传递内容,并且 jar 文件可以位于计算机上的任何位置。
例如,要制作一个 bash 脚本,使用 Google 的 Closure Compiler 以与 bash 环境无关的方式压缩 JavaScript 代码:
#!/bin/bash
# Script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Path to Closure Compiler
COMPILER=$HOME/archive/closure-javascript.jar
# Java requires converting paths from UNIX to Windows under Cygwin
case "$(uname -s)" in
CYGWIN*) COMPILER=$(cygpath -w $COMPILER)
esac
# Java must be in the PATH
COMMAND="java -jar $COMPILER"
# Allow overriding default filename from the command line
cd $SCRIPT_DIR
rm *.min.js > /dev/null 2>&1
# Minify all files in the directory
for js in *.js; do
$COMMAND --js=$js --js_output_file=$(basename $js .js).min.js
done
该脚本应在 Cygwin 和 Linux 下正确执行。