4

I am trying to test the nohup command in the bash shell by executing a command in the background and logging out and back in again and expecting the output of the command to be in the nohup.out file. Here is the command I am trying to execute:

$ nohup (sleep 120; echo "job done") &

But I keep getting the error:

bash: syntax error near unexpected token `sleep`
  • 2
    Remove the subshell – Jesse_b Mar 3 '18 at 20:21
16

The nohup command is not a keyword; it can't be given a subshell as the command to run, and instead it requires an actual runnable command:

nohup bash -c 'sleep 120; echo "job done"' &

Bash is giving you a syntax error because it thinks you're trying to declare a function called "nohup", which is the only case where a bare parenthesis can appear in the second word on the command line:

nohup () { ... ; }

The error message is telling you (obscurely) that it expected to see the right parenthesis there and not the word "sleep".

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.