0

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]);
        }

}
4

1 回答 1

8

将波浪号放在单引号中:

java mypackage.MyClass '~'

我假设您使用的是 bash shell,在这种情况下~会自动扩展到您的主目录。把它放在单引号中告诉shell不要扩展它。

于 2013-09-15T04:46:31.787 回答