Question

How do I run my script : sh Calculator.sh 1 + 2 * s\(4\)

s(x) is sinus of x

Now I wanna do something like this: sh Calculator.sh 1 + 2 * s(4)

and this give me error: bash: syntax error near unexpected token('`

Please help me.

Was it helpful?

Solution

Use quotes?

sh Calculator.sh "1 + 2 * S(4)" 

OTHER TIPS

You will need to quote or escape the parentheses (and *, and any other shell metacharacters) in order to pass them to your script. When the shell sees a command like sh Calculator.sh 1 + 2 * s(4), it runs it parses the command (doing things like replacing * with a list of filenames and getting confused by the parentheses) before it even looks at the first word to decide what command is being executed. The error you're seeing occurs long before your script starts (and in fact, prevents your script from ever starting), so there's nothing you can do in your script to avoid it.

Shell commands must obey shell syntax. There's no way to make an exception for your command (short of editing the shell program itself, that is).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top