Solved

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

Posted on 2004-09-14
8
750 Views
Last Modified: 2013-12-26
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
Comment
Question by:jesplumbob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 250 total points
ID: 12057745
(find / -name foo > /dev/tty) >& /dev/null
0
 
LVL 19

Expert Comment

by:NickUpson
ID: 12058348
in case /dev/tty is not your screen

find / -name foo 2>/dev/null
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12058447
/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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 48

Expert Comment

by:Tintin
ID: 12059414
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
 
LVL 38

Expert Comment

by:yuzh
ID: 12060736
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12063282
> "Csh Programming Considered Harmful"
and for "bash Programming Considered Harmful":
    :() { :; };:

0
 
LVL 2

Expert Comment

by:rajeshp_69
ID: 12064565

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
 

Author Comment

by:jesplumbob
ID: 12066403
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

627 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