I'm doing math parser where I need to have input through command line.
So I did it but I have problem that bash is giving me error with -bash: syntax error near unexpected token('` when I input expression like 3*(2). On normal input it's working.
-
1Please paste some codeCaius– Caius2016-07-28 18:38:25 +00:00Commented Jul 28, 2016 at 18:38
-
oh I solve it.. I need it input like '3*(2)' damnJacob Leet– Jacob Leet2016-07-28 18:39:21 +00:00Commented Jul 28, 2016 at 18:39
-
1You should clarify what 'normal input' is (with an example or two).Jonathan Leffler– Jonathan Leffler2016-07-28 18:44:47 +00:00Commented Jul 28, 2016 at 18:44
-
It's math parser so my input was like ./myprog 'sin(25) - 3*(35-1)' etc without these ' ' it wasn't working :)Jacob Leet– Jacob Leet2016-07-28 18:46:28 +00:00Commented Jul 28, 2016 at 18:46
Add a comment
|
1 Answer
Certain characters such as *, (, and ) have special meaning to the shell. You'll need to escape them with a backslash when calling your program:
./myprog 3 \* \( 2 \)
2 Comments
Jonathan Leffler
@JakubStibůrek: backslashes or single quotes both work — and the reason is what dbush stated; they have special meanings to the shell.
John Bollinger
Double quotes would probably work too for the kinds of inputs involved, but single quotes are safer.