It is currently Tue, 07 Dec 2021 01:38:35 GMT

Author Message
 Output Redirection in Sh Shell
     I had written a Unix command in a Perl script that used output
redirection to write its standard out and error out to a file.
However I used the C shell notation, like so:

     date >$ HmmDate

The error message I got seemed to indicate that the shell I was
working with was "sh", not "csh".  What would be the equivalent
command to redirect the standard and error out to this file,

     While we're on the subject, what is a good book on the "sh"
shell that I can read?  I seem to be stuck with the "sh" shell here,
and anyhow the prevailing opinion of most people I've talked to seems
to indicate that in many ways "sh" is superior to "csh".

     Another by-the-way:  is "sh" the Korn Shell?  If not, what is it?

                                ---Kevin Simonson
                                   Reverence the eternal.

Sent via

 Mon, 21 Jul 2003 06:29:46 GMT   
 Output Redirection in Sh Shell

Try one or both of the following:

      date &> myFile
      date > myFile 2>&1

You could try looking at a few on-line resources first. Try this as a start:

A short tutorial at:

For books, try a search of


* 'sh' refers to the Bourne Shell, the first of the major shells

* 'csh' refers to the C Shell
* 'tcsh' refers to the Extended C Shell

* 'ksh' refers to the Korn Shell, an extension of the Bourne shell
  combining features from the C shell, and other enhancements

* 'bash' refers to the 'Bourne-again' Shell, the GNU version of
  the Bourne shell with many extensions and enhancements

I hope this helps.

 Mon, 21 Jul 2003 08:21:17 GMT   
 Output Redirection in Sh Shell
date &> myFile

would not work.  It would put the date command into the background.  This would
give rise to 2 scenarios:

1]  If the background command process is able to write to its controllling
terminal, the date will be output to the terminal and myFile would be empty.
2] If "stty tostop" is in effect, the process will be stopped with the message
"Stopped (SIGTTOU)" and nothing will be sent to myFile.

The correct option is
    date > myFile 2>&1

 Mon, 21 Jul 2003 08:30:32 GMT   
 Output Redirection in Sh Shell

It would appear, then that this is a 'bash'-only option; I tested this and
it works perfectly well under 'bash'.

My apologies for not being more specific. Thanks for the correction.


Anthony Borla

 Mon, 21 Jul 2003 09:43:55 GMT   
 Output Redirection in Sh Shell

Scripting in the C-shell is generally considered harmfull. (Tom
scource: "Unix Power Tools" see for  details

A good book for beginners in scripting, there are many of them, I liked
"shell programming in 24 hours "
for basic syntax. After those 24 hour, IMHO, absolutely _nothing_ can beat

"Shell scripting by example." (see for details).
A book that shows complex scripts and a line by line explenation.

 Mon, 21 Jul 2003 22:07:39 GMT   
 Output Redirection in Sh Shell
"sh" usually refers to the Bourne shell, the gold
standard which has been around for 25 years or so. "man
sh" tells you all you need to know in less than 15
printed pages.

 Mon, 21 Jul 2003 22:55:42 GMT   
   [ 6 post ] 

Similar Threads

1. Output redirection in shell script

2. Output redirection while reformatting the output

3. root's shell, /sbin/sh, /bin/sh and /usr/ksh

4. sh feature: redirection of flow control bug

5. error redirection in sh (possible flame receptacle?)

6. Circular redirection in sh

7. sh I/O redirection

8. Redirection of *while* in sh

9. /bin/sh redirection of stdin, stderr woes

10. output redirection

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software