Unix Shell - in-here documents

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > April 2005 > in-here documents





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author in-here documents
Alejandro Nieto

2005-04-27, 5:58 pm

Hi,

i do not have big experience in ksh so i was wondering if the following
is feasible. I'm having ksh errors though probably somebody out there
can give me a quick help to sort it out.

I have somethign like:

--------------------

#!/bin/ksh

document()
{
<<EOF
a b c d e
a b c d e
<<
}

otherFuntion()
{
while read aa bb cc dd ee
do
echo $aa $bb $cc $dd $ee
done < document

---------------------------------

expected result will be:
a b c d e
a b c d e



i know 'while do' needs to read from standar output or from a file, but
how i could do the in-here document inside of document function to feed
the while loop?

Any link to a ksh web page or like will be really appreciated.

thanks a lot in advance,
Alejandro
Ed Morton

2005-04-27, 5:58 pm



Alejandro Nieto wrote:

> Hi,
>
> i do not have big experience in ksh so i was wondering if the following
> is feasible. I'm having ksh errors though probably somebody out there
> can give me a quick help to sort it out.
>
> I have somethign like:
>
> --------------------
>
> #!/bin/ksh
>
> document()
> {
> <<EOF
> a b c d e
> a b c d e
> <<
> }
>
> otherFuntion()
> {
> while read aa bb cc dd ee
> do
> echo $aa $bb $cc $dd $ee
> done < document
>
> ---------------------------------
>
> expected result will be:
> a b c d e
> a b c d e

<snip>

It's just called a "here document".

-----------
#!/bin/ksh

document()
{
cat <<EOF
a b c d e
a b c d e
EOF
}

otherFunction()
{
document | while read aa bb cc dd ee
do
echo "$aa $bb $cc $dd $ee"
done
}

otherFunction
-----------

By the way, you should always quote your variables.

Regards,

Ed.
Alejandro Nieto

2005-04-27, 5:58 pm



Thanks a lot Ed. And thanks again for the correction about "here document"

cheers
Alejandro
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com