문제

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.

도움이 되었습니까?

해결책

Use quotes?

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

다른 팁

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top