Piping here documents
Kris Stephens [Hail Eris!]
krs at uts.amdahl.com
Sat Feb 9 02:53:06 AEST 1991
In article <6061 at idunno.Princeton.EDU> rhl at grendel.Princeton.EDU (Robert Lupton (the Good)) writes:
>What's the best way of piping a here document into a long shell script?
I usually do multi-line here-documents in a function...
--- start sample ---
:
# sh or ksh
#
# Database search function
#
searcher() {
dbquery $DBNAME <<EOF
retrieve ( r.a, r.b, r.c ) where
r.a = $astring and
r.b = $bstring
$sort
EOF
}
#
# Start of mainline code (usually done with getopts and the like,
# so this is just a brief alternative without arg testing etc.)
#
astring="${1:-*}"
bstring="${2:-*}"
sort="sort by ${3:-r.a}"
DBNAME="${4:-mydatabase}"
#
# call searcher to get records from the db,
# sed to delete the last line (row count),
# and lp the results.
#
# (Talk about nonsense!! :-)
#
searcher |
sed '$d' |
lp
exit $?
--- end sample ---
...Kris
--
Kristopher Stephens, | (408-746-6047) | krs at uts.amdahl.com | KC6DFS
Amdahl Corporation | | |
[The opinions expressed above are mine, solely, and do not ]
[necessarily reflect the opinions or policies of Amdahl Corp. ]
More information about the Comp.unix.shell
mailing list