2

I am trying to write a simple java calculator program capable of addition, multiplication, subtraction, and division.

Within Eclipse, it works perfectly. But when I try to run it on Ubuntu Terminal, the symbol "*" is not recognized as an argument.

For example, when I type: java Calculate 7 * 8, the program does not read in the input as three pieces of arguments.

I am curious to know the cause of this problem and possibly a fix to this.

ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79
hao
  • 635
  • 2
  • 8
  • 20

1 Answers1

5

When you do this on most command lines, the * is going to be expanded to the list of files in the directory. Try escaping it with quotes...

java Calculate 7 "*" 8

or

java Calculate 7 '*' 8

Edit: Thanks @Danny Daglas

Todd
  • 30,472
  • 11
  • 81
  • 89
  • 3
    "" are good quotes to use on Windows. '' are preferable for Ubuntu because `"*"` will still expand to "all files in the current working directory" in most Unix shells. `'*'` will not. – Danny Daglas Jan 20 '15 at 01:59
  • On Windows the original line is still available. Unlike UNIX, that is what is passed to the process. The `java.exe` wrapper then has that parsed into bad old `argv` and `argc`. However, there isn't a standard way to get at the original line. – Tom Hawtin - tackline Jan 20 '15 at 02:04