So I have a script that I want to run as root, without hangup and nicely. What order should I put the commands in?
sudo nohup nice foo.bash &
or
noh
Disagree with other answers. I recommend:
sudo nohup nice foo.sh
I have observed nohup sudo #fail -- ie nohup is not always transferred to sudo'd sub-sub-processes (this was for certain /etc/init.d scripts on Ubuntu which delegated to yet other scripts). Not sure why, certainly surprising, but was the case and took a good wee while to debug.
(I note others report niceness not being passed through, so seems best to put it last ... although if in doubt on your OS put nice earlier, because nice not taking effect is usually less of a problem than nohup not taking effect!)
Note that sudo nohup leaves nohup.out owned by root, also as has been mentioned, but that's fixed with a:
sudo nohup nice foo.sh >> /tmp/foo.stdout.log 2>> /tmp/foo.stderr.log