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>.
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.
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.