Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to do something fairly simple:

$ ( cd /opt/myprogram && ./myprocess.sh >/dev/null 2>&1 & ; disown $! )
-bash: syntax error near unexpected token `;'

How can I bust out a one-liner to, in a sub-shell, execute a given script from a given folder, nulling the output, and sending it to the background?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

The problem is that you are using both & and ; together. They are both command terminators, and can not be used at the same time. Here is your example fixed:

( cd /opt/myprogram && ./myprocess.sh >/dev/null 2>&1 & disown )
share|improve this answer

The nohup utility was designed for pretty much what you're looking for:

Usage: nohup COMMAND [ARG]...
  or:  nohup OPTION
Run COMMAND, ignoring hangup signals.

If standard input is a terminal, redirect it from /dev/null.
If standard output is a terminal, append output to 'nohup.out' if possible,
'$HOME/nohup.out' otherwise.
If standard error is a terminal, redirect it to standard output.
To save output to FILE, use 'nohup COMMAND > FILE'.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.