Solved

tcsh redirection

Posted on 1999-01-27
10
743 Views
Last Modified: 2011-09-20
How can I redirect stderr to /dev/null, and keep stdout going to stdout? Something like:
(foo > stdout) >& /dev/null
But that doesn't work, obviously. Easy in bash, but I can't figure it out in tcsh.
thanks,
trails
0
Comment
Question by:trails
  • 4
  • 4
  • 2
10 Comments
 
LVL 3

Expert Comment

by:mliberi
ID: 2009423
"bash -c 'foo 2>/dev/null'" isn't acceptable?
0
 

Author Comment

by:trails
ID: 2009424
Yeah, it's okay, I guess I would just like to know if it's possible in tcsh. But I don't think it is. You can redirect to /dev/tty, but that's a hack that doesn't work very well at all.
Thanks for the comment,
trails
0
 
LVL 3

Expert Comment

by:mliberi
ID: 2009425
proposing the same as an answer:

"bash -c 'foo 2>/dev/null'"
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2009426
it can be done in tcsh too, without using bash
0
 

Author Comment

by:trails
ID: 2009427
I'm sorry, I'm going to have to reject that answer on principle. First: I already knew how to do it in bash, as I stated in my original question. Second: someone says it's possible, so if there's an answer, that deserves the points.
trails
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 2009428
(your_command >`tty`)>&/dev/null

This is the only case where redirecting in csh/tcsh is more cumbersome than in other shells, but it's well documented too.
Keep in mind that csh/tcsh was made for interactive usage, where an errorenous command's output usually is useless, while the error message is important (and not vice versa as you prefer in your situation ;-)
0
 
LVL 3

Expert Comment

by:mliberi
ID: 2009429
the proposed answer redirects output to /dev/tty, so stdout doesn't keep going to stdout (as the question stated).
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2009430
mliberi, what do think is the difference between stdout and /dev/tty (in this special case)?
BTW, it does not redirect to /dev/tty, more correctly to the shells tty; see man tty
0
 
LVL 3

Expert Comment

by:mliberi
ID: 2009431
There is a big difference between tty and stdout.

Suppose your command has been placed in a script, let's say 'xxx'

By calling the script with the syntax "xxx >myfile" I would expect that the output of the script to be written to "myfile". With the command you gave the output would be placed on the screen.

from "tty" man page:
>  tty Command

>  Purpose

>  Writes to standard output the full path name of your terminal.

Do you still think that stdout and `tty` to be the same thing?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2009432
well I agree for the special case: script-file :-)
(you remember my comment: this special case?)

If you would do in a csh script, you would probably  to do it like:

   (your_command > tmp_file)>&/dev/null
  cat tmp_file

As I, said in my answer: redirecting stdout without stderr is not implemented in
csh/tcsh.
So trails no knows how to do it interactiv and in a script ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now