Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 766
  • Last Modified:

send cshell std out to screen and std error to /dev/null

I want to send the output of find to the screen and std error to the bit bucket using the c shell.
(find / -name foo > somefile) >& /dev/null  will send the output to somefile & then I could use 'cat somefile' to read the file but is there a  way to send the output of find directly to the screen?

0
jesplumbob
Asked:
jesplumbob
1 Solution
 
chris_calabreseCommented:
(find / -name foo > /dev/tty) >& /dev/null
0
 
NickUpsonCommented:
in case /dev/tty is not your screen

find / -name foo 2>/dev/null
0
 
chris_calabreseCommented:
/dev/tty is _always_ your screen. That's what it does.

Meanwhile, the 2>/dev/null syntax doesn't work in csh, only sh and variants.

One reason few people use csh any more since ksh and bash have had all the main features that people switched from sh to csh n the first place, like history and job control, for over 15 years
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TintinCommented:
From the "csh considered harmful"

1a. Writing Files

In the Bourne shell, you can open or dup arbitrary file descriptors.
For example,

    exec 2>errs.out

means that from then on, stderr goes into errs file.

Or what if you just want to throw away stderr and leave stdout
alone?    Pretty simple operation, eh?

    cmd 2>/dev/null

Works in the Bourne shell.  In the csh, you can only make a pitiful
attempt like this:

    (cmd > /dev/tty) >& /dev/null

But who said that stdout was my tty?  So it's wrong.  This simple
operation *CANNOT BE DONE* in the csh.


Along these same lines, you can't direct error messages in csh scripts
out stderr as is considered proper.  In the Bourne shell, you might say:

      echo "$0: cannot find $file" 1>&2

but in the csh, you can't redirect stdout out stderr, so you end
up doing something silly like this:

      sh -c 'echo "$0: cannot find $file" 1>&2'
0
 
yuzhCommented:
chris_calabrese's comment (http:#12058447) is correct!

Just add a bit more infor to see if I can help you understand it.

In csh/tcsh, you can redirect stdout with ">", or stdout and stderr together with ">&" 
but there is no direct way to redirect stderr only. The best you can do is:
        ( command >stdout_file ) >&stderr_file

which runs "command" in a subshell;  stdout is redirected inside the subshell to stdout_file,
and both stdout and stderr from the subshell are redirected to stderr_file, but by this point
stdout  has already been redirected so only stderr actually winds up in stderr_file.

For shell scripting you should use sh/ksh/bash, it is a lot easy to do things than csh/tcsh.

please have a look at "Csh Programming Considered Harmful":
http://www-dbs.inf.ethz.ch/~fessler/csh-whynot.html

BTW, csh was my default login shell 10+ years ago, I changed my default shell to ksh, and
write script in ksh.
0
 
ahoffmannCommented:
> "Csh Programming Considered Harmful"
and for "bash Programming Considered Harmful":
    :() { :; };:

0
 
rajeshp_69Commented:

Just try out the following command:

(find ./ -name foo > `tty` ) >& /dev/null

I am sure that this must work for you as I also uses csh for some applications.

Bye
0
 
jesplumbobAuthor Commented:
I gave chris' answer an A because it was fast, short and complete. In my case going to bash isn't good because the main reason for my system is to support a high-end CAD app and it requires me to source some scripts that assume the c shell. I could jump back and forth between shells but that's complicated and I like simple.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now