I was starting jboss recently in background in Linux and saw that if you run command as follows:

nohup ./startjboss.sh > server.log &

Output is :

[1] 18835
[root@cnt5-01b downloads]#

The terminal for the next command appears directly.

However, if I run the command as follows:

nohup ./startjboss.sh & > server.log

Then the output is:

[1] 19223
[root@cnt5-01b downloads]# nohup: appending output to `nohup.out'

Then, when I press enter, it returns to:

[root@cnt5-01b downloads]#

which is the terminal where I can write next command.

Why is there a difference in behavior (an extra Enter needed)? This is a very small thing, not even a problem; but I just want to know.


When you place the &, you're telling the shell to run what precedes it in the background and continue with a new command.

When you put it at the end of the line, there's no command after so the shell returns to interactive mode.

When you place it in the middle, the shell interprets the rest of the line as a new command. That command redirects the standard output of nothing to server.log. Since you're not redirecting the output of nohup, you now see it on the terminal. Since the shell had already redrawn its PS1 before, you see that line of output as if it were a command, but it's simply output from a background job. You can type your new command without even pressing enter before (though it's not that clear when you read it later).

| improve this answer | |

Well basically, when you run a command with & after it, you are loosing some functionality.

Take this as an example, make a script that does nothing but returning 2 for example.

  • run the script normally, issue echo $? and you will see the output 2.
  • run the script with & after it, run echo $? and you will see the output 0.

Also, when running nohup ./startjboss.sh & > server.log, if you check the server.log file, you'll see that is empty, that's because the output of your background process will be 0 on successful termination, but because you didn't echo it into server.log, so nothing will be actually written to server.log.

| improve this answer | |

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.