error piping nohup to /dev/null

Hi,

I have a script as follows:

#!/bin/sh

nohup ./my_program >& /dev/null &

However, i get a "Generated or received a file descriptor number that is not valid" whenever I run it.

running the command up in prompt is ok though.

if i change the first line to #!/bin/csh
i get a then: then/endif not found.

Pardon my ignorance but I really can't solve this problem.

Can anyone kindly offer some advice?

try getting rid of the first '&'.

ScatterBrain is right - but you may want to send any errors to std err for inital debugging.

try:


#!/bin/sh

nohup ./my_program > error.log 2>&1 

...or how about...

nohup ./my_program >/dev/null 2>error.log &

that is, if you don't care about standard output... but just wanna see stderr messages.

if you intend to do this a lot... or permanently with this script, you may want to consider adding within the script something like this:

exec 1>/dev/null
exec 2>error.log (or exec 2>&1 if you want no output at all)

Thanks! U guys are great! I removed the first & and it really works.
I'm still baffled why including the first & will work in the command prompt but
not within the script though.