Where is the tutorial for input and ouput redirection ?

Where is the tutorial for input and ouput redirection ?

Post by Sam Ch » Fri, 08 Dec 1995 04:00:00



I am a new unix script writer. I am confusing about the usage of 2>&1,
4 < file, 2>>&1 ... etc. Is anyone know where is the tutorial for input
and output redirection ?
 
 
 

Where is the tutorial for input and ouput redirection ?

Post by Charles Rot » Sun, 10 Dec 1995 04:00:00




>I am a new unix script writer. I am confusing about the usage of 2>&1,
>4 < file, 2>>&1 ... etc. Is anyone know where is the tutorial for input
>and output redirection ?

Check out "UNIX Power Tools", by Jerry Peek, Tim O'Reilly, Mike Loukides,
and a cast of _thousands_.  8^)  O'Reilly & Associates/Random House.
May, 1994 (unless a later edition is out now, which very well may be .. 8^)
ISBN 0-679-79073-X.

Any decent technical book store ought to have it in stock.  It'll set you
back $60, there's a CD-ROM in the back.

Chapter 14 is _all_ _about_ I/O redirection in the Bourne and C shells.
Chapters 46, 47, and 48 are on Bourne shell programming.  Chapter 49 is
on the excellent reasons why C shell _scripting_ should be avoided like
exposure to the AIDS virus.  8^)  (Though it _does_ have many shining
virtues as an _interactive_ shell.)  

You don't have to read the book from front to back, BTW .. it is _DESIGNED_
to be browsed.  !!!!  The cross-indexing on the page margins is the best
I've ever seen.  

IMHO, this is the best single book on the UNIX operating system I have ever
seen in my entire wretched, miserable life.  8^)  Lie .. steal .. kill ..
but get a copy into your personal library.  8^)  

Oh, BTW .. the chapters on scripting and I/O redirection are the clearest
expositions on that topic I have ever come across.  

PS:  The entire O'Reilly line kicks some serious *as documentation.
O'Reilly and Associates is to UNIX reference works what Toyota is to
automobiles.  

 
 
 

Where is the tutorial for input and ouput redirection ?

Post by Dave Bro » Wed, 13 Dec 1995 04:00:00


[on _Unix Power Tools_
: Chapter 49 is on the excellent reasons why C shell _scripting_
: should be avoided like exposure to the AIDS virus.  8^) (Though it
: _does_ have many shining virtues as an _interactive_ shell.)

Namely, ! history and (something like) completion.

Fortunately, those have both been conveniently put into bash, which is a
Bourne shell derivative, and zsh, which is a Korn shell derivative.

I do NOT like not having my stdout and stderr easily separable, or
having to type a carriage return somewhere--doesn't really matter where,
just somewhere--in a for or an if construct, or having the shell not be
able to put a carriage return in a quoted string, or having conniptions
whenever you use an exclamation mark without any way of turning it off.

I am SOOO tempted to just say 'rm /bin/csh /usr/contrib/bin/tcsh' on my
systems.

This has been a Rant.

Oh yeah--and SCO's csh thinks that true is false and false is true.  *sigh*

--Dave

 
 
 

1. Odd ouput redirection in background script

Today I was cooking up a small program to save me the trouble of having to
wait for my rsh's to finish:

/* Background Processes */
#include <stdio.h>

main(argc, argv)
int argc;
char *argv[];
{
  if (fork())
      exit(0);
  execvp(argv[0],&argv[1]);
  printf("OOps\n");

I used the following script to give it a test:

#!/bin/csh

ls > /tmp/tt$$

Then I typed, "background test_scr" to give it a test and it worked fine;
I got the output in the file in /tmp and everything.  I then tried to use
it with rsh and it was a complete failure.  Right away I remebered that
the child process inherits everything, so I needed to close stdin and
stdout.  So the program became:

/* Background Processes */
#include <stdio.h>

main(argc, argv)
int argc;
char *argv[];
{
  if (fork())
    exit(0);
  close(0);
  close(1);
  execvp(argv[0],&argv[1]);
  printf("OOps\n");

Easy.  Now I gave it a test with, "background test_scr" and it wrote the
directory listing to my screen.  My question: Why?  Not only did I close
stdout, but I also had it re-directed in the script.  Is it a probelem
with the shell?

I've gotten the program to work the way I want it to, now, but I am
baffled by the odd behavior.

Thanks for any info.

--
Ian Flanigan



2. Full Duplex/Half Duplex

3. serial setup error :Input/ouput error..... using setserial

4. external modem as telephone

5. tcgetattr: Input/ouput error(5)

6. What does getppdent: line too long mean?

7. Need Input for Development Tutorial

8. PPPD error

9. Input redirection newbie question

10. input redirection

11. Question regarding input redirection and pipes

12. Mixing redirection and std input (Question)

13. How detected eof on input redirection?