0

What is the difference between these 2 below lines?

nohup $CATALINA_HOME/bin/startup.sh $CATALINA_HOME 2> /dev/null &

nohup $CATALINA_HOME/bin/startup.sh $CATALINA_HOME > /dev/null &

I've these lines in 2 of my projects having Tomcat server. One of them is having 2> & other one is just with > symbol.

Appreciate youe help!

Note: The line with 2> if ran in CentOS runs fine but the other one gives warning: "nohup: redirecting stderr to stdout"

Thanks!

Freephone Panwal
  • 1,547
  • 4
  • 21
  • 39

1 Answers1

2

Both redirect to /dev/null the first one redirects stderr the second one redirects stdout.

More on that: http://www.tldp.org/LDP/abs/html/io-redirection.html, also a few examples always from tldp http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html

Side note: if you want to redirect both stdout and stderr you could do:

nohup $CATALINA_HOME/bin/startup.sh $CATALINA_HOME &> /dev/null &
Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106
  • When I run the 2nd line on Red Hat 5.7 OS, it does not give me any warning but when the same is run on CentOS 6.4, it gives warning "nohup: redirecting stderr to stdout", how can I avoid this warning in CentOS? – Freephone Panwal May 15 '13 at 21:26
  • I've updated my answer, look at the last command, that redirects both `stdout` and `stderr` – Alberto Zaccagni May 15 '13 at 21:32
  • 1
    `&>` is a non-standard mechanism. It redirects both streams in some shells (eg bash) and behaves completely differently in others (eg dash, which conforms to the sh language specifications and treats the `&` as a separate token, running the command in the background and then truncating the file to which you intended to direct output.) – William Pursell May 15 '13 at 21:39
  • Then it depends on the sh of the OP. Thanks for that though. – Alberto Zaccagni May 15 '13 at 21:40
  • Quick question: Why red hat OS does not give the warning message for 2nd line where as centOS gives warning? – Freephone Panwal May 15 '13 at 21:48