更新:
我有一个可行的总体解决方案,但我不喜欢它:
jjs> NANO_HOME = '"/Users/XXXXXX/Desktop/TEST DIR"'; jjs> $EXEC('xargs ls',"${NANO_HOME}");
我正在使用 Java 8 Nashorn 执行一些 shell 脚本,如果目录名称包含空格,我在目录中列出文件时遇到问题:
$ jjs -scripting
jjs> `ls /Users/XXXXXX/Desktop/`
TEST DIR
jjs> `ls /Users/XXXXXX/Desktop/TEST DIR`
jjs> $ERR
ls: /Users/XXXXXX/Desktop/TEST: No such file or directory
ls: DIR: No such file or directory
jjs> `ls "/Users/XXXXXX/Desktop/TEST DIR"`
jjs> $ERR
ls: "/Users/XXXXXX/Desktop/TEST: No such file or directory
ls: DIR": No such file or directory
jjs> `ls /Users/XXXXXX/Desktop/TEST\u0020DIR`
jjs> $ERR
ls: /Users/XXXXXX/Desktop/TEST: No such file or directory
ls: DIR: No such file or directory
jjs> `ls /Users/XXXXXX/Desktop/TEST\ DIR`
jjs> $ERR
ls: /Users/XXXXXX/Desktop/TEST: No such file or directory
ls: DIR: No such file or directory
我已经尝试了几十种变化,但没有任何效果......