Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Poll: C-Shell: Send STDOUT & STDERR to a file?
Poll Options
C-Shell: Send STDOUT & STDERR to a file?

You must log in and have one post to vote in this poll. If you don't have an account, you can register here.
Results will be available after the polls close.

The nominees are:

cmd >& file
cmd & file
Hahaha! I use bash or zsh! It's easy for us!

  Search this Thread
Old 09-08-2003, 03:16 PM   #1
Registered: Aug 2003
Location: Berkeley, California, USA
Distribution: Red Hat Enterprise Linux, Debian & Ubuntu
Posts: 92

Rep: Reputation: 16
CSH: "cmd >& file" or "cmd </dev/null >& file"

Hello Everyone,

I just started a new job where they use alot of CSH scripts, and had a question about how to send both standard output and standard error to a file.

My Unix in a nutshell book says to use this method:

cmd >& file

This is the method that I am familar with.

However, at my new work place, the 'cmd >& file' isn't used at all, and instead all of the scripts use the following method:

cmd < /dev/null >& file

cmd in this case does NOT take anything from standard input. Why would someone do this? It seems pointless.

My coworkers think I am crazy to use the first method, but nobody can explain why the second method is better (They're crazy!)

Can anyone explain the difference between these two methods?

Thanks for your help,

-= Stefan
Old 09-08-2003, 05:19 PM   #2
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
both direct stdout and stderr to file, but with 'cmd >& file' if cmd (unexpectedly)asks for input then it will just sit there and wait, 'cmd < /dev/null >& file' guarantees the program does not sit there waiting for input.

if you KNOW cmd will never ever take input then use method 1 but i prefer to play it safe and plan for the future, so i would use method 2 as it will work when cmd is updated.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault on toplevel = XtVaAppInitialize(&app, "Email", NULL, 0, &argc, cbranje Programming 0 02-19-2005 01:06 PM
Differences of "make" in Kdev and cmd line srisner Linux - Software 1 12-23-2004 10:44 AM
SpamAssassin Error "spamd: no response to STREAM cmd, Success" and other errors PlorkZ Linux - Software 1 11-18-2004 05:16 PM
Is there an equivalent cmd to "chkconfig (redhat)" in Debian? davidas Debian 3 04-08-2004 11:54 PM
decrypting a file using "crypt" & "rot13" JAMZM101 Solaris / OpenSolaris 1 03-07-2004 10:32 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:36 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration