更新:
我有一种可行但很烦琐的解决方案:
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
我尝试了数十种变化,但都没有用...
\\
)? - Bergijjs
工作的方式。 - Stuart Marks