How to quit from a script?

hi all,

I am facing problem in shell scripting while using exit command, when ever i run a file using . ./<filename>, when i run the sae script as sh <filename> the script does not close the windows. since my script has function calls i have to use . ./ <filename>.

Could any one tell me where i am going wrong?

Thanks

Post the script here.

When you use 'sh script' you're invoking another shell to run the script while '. ./script' uses the current shell to parse the script.

sorry for the slight delay, had to write a new one to give it to you all. this is in essence the logic of my script.

function hello
{
echo "testing exit"
res=$?
return $res
}
# main
hello
if [ $res -eq 0 ] ; then
exit 1;
fi

The debug code is self explanatory

% ksh -x hello.sh
+ hello
testing exit
+ [ 0 -eq 0 ]
+ exit 1
                                                                                                                                                                                                              sh 
sh -x hello.sh
+ function hello
hello.sh: function: not found
+ echo testing exit
testing exit
res=0
+ return 0
hello.sh: cannot return when not in function

I am well aware of the useage of sh and . ./ when i use exit 1 without a function call and run the script, the script doesnt close the putty session, however when i run the script with a function and now i use . ./ the script closes the putty session.

How could I avoid it?

Thanks.

This is by design. The script is not supposed to close your putty session (it closes its own subshell). If you are sourcing the script (using . ) then it is, since you are calling exit in your current shell environment so it will close that.

:eek:

function hello ()
{
....

The correct syntax is either

name () {
}

or if the shell allows it:

function name { 
}

So I do not think there is a problem there.