[comp.unix.shell] piping into read in ksh

davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) (09/29/90)

  This saved me a lot of time when I found it. Works in ksh, someone
could let me know if it works in bash.

#!/bin/ksh

# This is a demo of piping stuff into read to break it into parts
# using ksh piping a command into read. ksh doesn't use a subshell for
# this, so the values read are preserved.
#
# this is often done with set, which messes up the arguments

# this is a demo of copying news articles and concatenating several
# in some cases, using the number of the first article as the
# destination filename. The names are fixed because (a) you normally
# do this interractively, and (b) it's only a demo.

for n in 101 "102 105 117" 200 212 "214 238 261" 302
do
 echo $n | read first1 rest
 echo "(cd /news-spl/comp/misc;cat $n) > myrefs/$first1"
done

# author: Bill Davidsen (davidsen@crdos1.crd.ge.com)

-- 
bill davidsen	(davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
    VMS is a text-only adventure game. If you win you can use unix.