davis@pacific.mps.ohio-state.edu ("John E. Davis") (04/28/91)
Hi, 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. Thanks, -- John bitnet: davis@ohstpy internet: davis@pacific.mps.ohio-state.edu
tchrist@convex.COM (Tom Christiansen) (04/28/91)
From the keyboard of davis@pacific.mps.ohio-state.edu (John E. Davis): : In VMS DCL I can do: : $ create post_news.txt : $ deck : 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. Sounds like you want the ``here-is'' notation: cat >post_news.txt <<EOD blah blah ... etc .. EOD In Bourne-compatible shells (and perl) you can control whether variables get interpolated in the intervening text: just quote the token (in this case EOD), and you quote the text. The csh, to no one's great surprise, has no such ability. --tom
hunt@dg-rtp.rtp.dg.com (Greg Hunt) (04/28/91)
In article <DAVIS.91Apr27183503@pacific.mps.ohio-state.edu>, davis@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@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.
torek@elf.ee.lbl.gov (Chris Torek) (04/28/91)
In article <1991Apr28.003414.26784@convex.com> tchrist@convex.COM (Tom Christiansen) describes `here-documents', and concludes with >In Bourne-compatible shells (and perl) you can control whether variables >get interpolated in the intervening text: just quote the token (in this >case EOD), and you quote the text. The csh, to no one's great surprise, >has no such ability. Actually, it does. It is merely somewhat annoying about it. In sh, cat << \end foo end and cat << 'end' foo end do the same thing. In the C shell these must be spelled as cat << \end foo \end and cat << 'end' foo 'end' respectively. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov
mark@loki.une.oz.au (Mark Garrett) (04/29/91)
From article <DAVIS.91Apr27183503@pacific.mps.ohio-state.edu>, by davis@pacific.mps.ohio-state.edu ("John E. Davis"): > In VMS DCL I can do: > > $ create post_news.txt > $ deck > > Hi, > > In VMS DCL I can do: > > .... etc.... > $ eod > $ exit > $ create post_news.txt Hi, In VMS DCL I can do: .... etc.... $ exit The $deck $eod aren't needed it will work as above cat > post_news.txt <<EOD Hi, In Unix I can do: sh csh ksh etc... and many many other things that leave DCL looking brain dead ie just look at for looks in sh/ksh , DCL for ? , nothing ! .... etc.... EOD -- Mark Garrett Internet: mark@loki.une.oz.au Phone: +61 (066) 20 3859 University of NewEngland, Northern Rivers, Lismore NSW Australia.
mark@loki.une.oz.au (Mark Garrett) (04/29/91)
From article <DAVIS.91Apr27183503@pacific.mps.ohio-state.edu>, by davis@pacific.mps.ohio-state.edu ("John E. Davis"): > In VMS DCL I can do: > > $ create post_news.txt > $ deck > > Hi, > > In VMS DCL I can do: > > .... etc.... > $ eod > $ exit > $ create post_news.txt Hi, In VMS DCL I can do: .... etc.... $ exit The $deck $eod aren't needed it will work as above cat > post_news.txt <<EOD Hi, In Unix I can do: sh csh ksh etc... and many many other things that leave DCL looking brain dead ie just look at for looks in sh/ksh , DCL for ? , nothing ! .... etc.... EOD -- Mark Garrett Internet: mark@loki.une.oz.au Phone: +61 (066) 20 3859 University of NewEngland, Northern Rivers, Lismore NSW Australia.
graf21@unibi.uni-bielefeld.de (0152) (05/03/91)
In article <1991Apr28.003414.26784@convex.com> tchrist@convex.COM (Tom Christiansen) writes: > >Sounds like you want the ``here-is'' notation: > > cat >post_news.txt <<EOD > blah blah > ... etc .. > EOD > My favourite way of using "here-documents" is to to pipe the "document" into the desired command through an intermediate "sed", like this: sed 's/^\.//' | your-command -options args <<EOD . .This is the input to "your-command", starting with a blank line .and ending with another one . EOD next-command ... Some "shar"-archivers (not all, unfortunately) use this trick. By specifying different patterns you could even introduce line-numbering, comments, indentation etc. into a "here-document". (sh ignores indentation when EOD is preceded by a minus sign, anyway.) Apart from improving readability, there can't possibly be confusion between the "EOD" line ending the input and a similar line inside it. The pattern after "sed 's/" must be designed carefully and "anchored" via "^" to make sure that "sed" delete no more characters from the input than intended. Sebastian Lisken Bielefeld University, Germany
andre@targon.UUCP (andre) (05/03/91)
In article <DAVIS.91Apr27183503@pacific.mps.ohio-state.edu> davis@pacific.mps.ohio-state.edu (John E. Davis) writes: > In VMS DCL I can do: > > $ create post_news.txt > $ deck > Hi, > $ eod > $ exit > How can I simulate this behavior in csh or sh? Solutions >requiring two files are not acceptable. Easy, use a "here document" like: $ mail foo <<eod > hi > etc... >eod and everything between the command and the first line that starts with eod is taken as stdin of mail. (you can also use <<! for brevity). -- The mail| AAA DDDD It's not the kill, but the thrill of the chase. demon...| AA AAvv vvDD DD Ketchup is a vegetable. hits!.@&| AAAAAAAvv vvDD DD {nixbur|nixtor}!adalen.via --more--| AAA AAAvvvDDDDDD Andre van Dalen, uunet!hp4nl!targon!andre