I am trying to figure out why I am getting a -bash: syntax error near unexpected token '(' when attempting to run a basic calculator java program from command line.
The project has been finished submitted and graded already, so no academic dishonesty intended.
In my terminal (macOs 10.13.6) I am running the program using:
java InfixExpressionEvaluator (a+b)*(c-9) "a=1 b=2 c=3";
where (a+b) * (c-9)
is the expression to be evaluated with the given variables following. However, every time I get -bash: syntax error near unexpected token '('. Is this due to the formatting of the expression (a+b) * (c-9)
? I am not familiar with bash scripting, but from some google searches it appear as though the terminal is attempting to interpret the '(' as part of a script, and to get around this I would need to place (a+b) * (c-9)
within quotations ie "(a+b) * (c-9)"
. Is this correct, or is there something I am missing?
The "expression to be evaluated" needs to be quoted because it contains several characters ( (
, )
, *
) that have special significance to Bash. This should work:
java InfixExpressionEvaluator '(a+b)*(c-9)' 'a=1 b=2 c=3'
No expansions are needed, so I used single quotes instead of double quotes. I removed the trailing ;
because Bash doesn't need it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.