将特殊变量(~波浪号)传递给 Java 程序 [英] Pass a special variable (~ tilde) to Java program
本文介绍了将特殊变量(~波浪号)传递给 Java 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试运行一个将~"波浪号作为命令行参数的 Java 程序.不幸的是,当我运行该程序时,我得到的是我不想要的主目录打印.我不知道我怎样才能达到同样的目标?
I am trying to run a java program that takes a '~' tilde as a command line argument. Unfortunately when I run the program what I get is my home directory printed which I do not want. I am not sure how can I achieve the same ?
public class Test {
public static void main(String[] args) {
System.out.println(args[0]);
}
}
推荐答案
将波浪号放在单引号中:
Put the tilde in single quotes:
java mypackage.MyClass '~'
我假设您使用的是 bash shell,在这种情况下 ~
会自动扩展到您的主目录.将它放在单引号中告诉 shell 不要扩展它.
I'm assuming you're using the bash shell, in which case ~
is automatically expanded to your home directory. Putting it in single quotes tells the shell not to expand it.
这篇关于将特殊变量(~波浪号)传递给 Java 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文