Can sh or csh do this VMS DCL trick??

Greg Hunt hunt at dg-rtp.rtp.dg.com
Sun Apr 28 12:01:09 AEST 1991


In article <DAVIS.91Apr27183503 at pacific.mps.ohio-state.edu>, davis at pacific.mps.ohio-state.edu ("John E. Davis") writes:
> 
>   In VMS DCL I can do:
> 
>      $ create post_news.txt
>      $ deck
>      
>         Hi,
> 
>           In VMS DCL I can do:
> 
>              .... etc....
>      $ eod
>      $ exit
>         
>   In other words, text following `$ deck' is treated as lines to be fed into
> the standard input of the previous command (create in this case).  Finally,
> the `$ eod' terminates input and control is passed back to the DCL command
> procedure.  How can I simulate this behavior in csh or sh?  Solutions
> requiring two files are not acceptable.

Sure, it can be done in either csh or sh the same way, using what is
called a "here" document, like this in a script:

    cat << EOD > post_news.txt
    In csh or sh scripts you can use a "here" document.
    After the text, put the "word" you put after the "<<"
    on a line by itself starting column 1.  That marks the
    end of the document that is right "here" in the script.
    EOD
    <your-next-command>

The shell puts the text into a temporary file that it points the
command's standard input to.

If you want the text from the user running the script, then just
redirect the standard input to the terminal instead, like this in
a script:

    cat < /dev/tty > post_news.txt
    <your-next-command>

When the user is done typing, he or she enters ^D (control-D), which
indicates end-of-file.

Take a look at the input and output redirection portions of the sh
and csh man pages for more details.

Gee, and only one file used, too ....

Enjoy!

-- 
Greg Hunt                        Internet: hunt at dg-rtp.rtp.dg.com
DG/UX Kernel Development         UUCP:     {world}!mcnc!rti!dg-rtp!hunt
Data General Corporation
Research Triangle Park, NC, USA  These opinions are mine, not DG's.



More information about the Comp.unix.questions mailing list