java - 如何将 "*"解析为 Java 程序作为输入参数?

标签 java shell

当我只使用java -Xxx *时,程序将获取当前路径中的所有内容作为输入。

如何仅获取 * 字符串作为输入?

最佳答案

这不是您在 Java 中所做的任何事情;这是 bash filename expansions 的行为:

After word splitting [...] Bash scans each word for the characters ‘*’, ‘?’, and ‘[’. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern (see Pattern Matching). If no matching filenames are found, and the shell option nullglob is disabled, the word is left unchanged.

正如 Jesper 在评论中指出的那样,您可以通过引用 * 字符来避免这种行为:

java -Xxx '*'

或者,正如 Ilya 所说,你可以逃避它:

java -Xxx \*

关于java - 如何将 "*"解析为 Java 程序作为输入参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43759094/

相关文章:

linux - 传输大文件时出错 : Argument list too long

ruby-on-rails - 在 bash 中执行 rake 命令

java - Java RMI 服务器在哪里监听?

java - Ant 构建失败, "[javac] javac: invalid target release: 7"

java - 在更改 Camel 版本时,War 未部署在 weblogic 中

MySQL备份并删除旧备份

linux - 如何找到隐藏文件

linux - 为所有后续调用更改 shell 内置函数(例如 echo)的定义,但仅限于当前 shell 的范围内

java - 使用 Java 的 Desktop 类在 IE 中打开 URL

java - Apache 服务器作为 Jboss 问题的代理