Syntax error at line 24: `(' unexpected

Hi,

I am getting an wired error.... the script is running fine when i run it manually... but the same when i try to run in nohup mode, i am getting error

if [ $(grep -c "My Daddy" processfile.txt) -ne 0 ]
      

Error:

syntax error at line 24: `(' unexpected

The above if is the 24th line!!! I dont understand the error @ all!

Works fine for me using ksh and bash when run from both command line and nohup'ed. What is your shell? if you are using the bourne shell, the "$( )" command substitution syntax is not supported. Use backquotes instead:

if [ `grep -c "My Daddy" processfile.txt` -ne 0 ]

And make sure you test for the existence of processfile.txt first too.

Make sure your script starts with a "shebang", which tells the login shell what shell to use when runnning the script:

#!/bin/ksh
.....
Rest of code...
1 Like

it workd!!! i am using

bash shell... so i used ``...

Thanks a lot!

The "$( )" command substitution syntax works in bash and is actually preferred over using backquotes as its easier to use if you need to nest commands. I suspect you are really using the bourne shell. What is your shebang line? if its "#!/bin/sh" then its most likely the Bourne shell. Try your original code with "#!/bin/bash" instead.

$(...) works in any POSIX shell, but not in classic Bourne shell..