Solved

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

Posted on 2004-09-14
8
748 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
has77  challenge 9 107
twoTwo  challenge 35 121
Line meaning 9 99
ERP and the other system process verification 5 26
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

752 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