Regarding functions

Hi,

I have a function or script like this.

show()
{
echo "Hi"
} | tee -a log
show

This creates a logfile and prints Hi in it. Now when I try to do the same for sql like this:

show()
{
sqlplus -s scott/tiger<<!
select * from details;
!
} | tee -a log
show
Then it gives me a error telling me that :show not found.

What am I doing worng here. Please put some light on this.

Thanks in advance

Hi,
Try this..if u want to remove sqlplus option remove it this will give u data only
or u can use EXIT; in ur script that will bring control back to ur script from sqlplus

show()
{
x=`sqlplus -s scott/tiger<<!
set echo off
set serveroutput on
set heading off
set feedback off
select * from details;
EXIT;
!`
echo $x>>log
}
#echo "before "
show

I can't recreate that result. What shell are you using?

show() { echo "Hi" ; }
will define a function but does not run it. No output occurs.

show() { echo "Hi" ; } | tee -a log
The pipeline forces creation of a subshell. The subshell defines a function then exits producing no output. The empty output is piped to tee. With the -a option, tee appends nothing to the file. Maybe the file had Hi from a previous run?. The pipeline exits. Now when the parent shell next encounters "show", it will have no idea what that is supposed to be.

show() { echo "Hi" ; }
show | tee -a log
is maybe what you are trying to do.

Or
show () { echo "Hi" | tee -a log ; }
show