home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / c_spec / execute / echo.c < prev    next >
C/C++ Source or Header  |  1986-02-20  |  990b  |  45 lines

  1. #include <stdio.h>
  2.  
  3.  
  4. /*    ECHO.C        Copy arguments to standard out. Useful
  5.  *            to see what the shell will do to wild-cards and
  6.  *    to print stuff from a shell script.
  7.  *
  8.  *    Usage:        echo arg...
  9.  *    Exit status:    always 0;
  10.  *
  11.  *    Copyright (C) 1986, Allen I. Holub. All rights reserved.
  12.  */
  13.  
  14. #define E(x)    fprintf(stderr,"%s\n", x)
  15.  
  16. main( argc, argv )
  17. char    **argv;
  18. {
  19.     register int    suppress_cr = 0;
  20.  
  21.     reargv(&argc, &argv);
  22.  
  23.     if( argc > 1 && argv[1][0] == '-' )
  24.         if( !(suppress_cr = (argv[1][1] == 'n')) )
  25.             usage();
  26.  
  27.     for(++argv; --argc > 0; printf("%s ", *argv++)  )
  28.         ;
  29.  
  30.     if( !suppress_cr )
  31.         printf("\n");
  32.  
  33.     exit( 0 );
  34. }
  35.  
  36. usage()
  37. {
  38.     E("Echo: Copyright (c) Allen I. Holub, All rights reserved\n");
  39.     E("prints its arguments to standard output. It's very useful");
  40.     E("for finding just how the shell expands arguments. Usage is:");
  41.     E("\n                   echo [-n] args\n");
  42.     E("If the -n is present, no newline is added to the output.");
  43.     exit( 1 );
  44. }
  45.