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?


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 )
  • I am trying a command on similar lines : bosh -e bosh -d service-fabrik ssh broker -c "tail -F /var/vcap/sys/log/service-fabrik-broker/service-fabrik-broker.log > /var/vcap/sys/log/service-fabrik-broker/error.log 2>&1 & disown" , but it doesn't seem to work. Any idea what could be wrong ? Thanks – akskap Apr 30 '18 at 13:24

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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