problem in CD command

hello guys,,
here is my problemia have written a code as below

var="vi"
if [ "$var" = "vi" ] ; then
cd <some path>
echo $PWD
fi

my problem is after exicution of this code the cintrol will return to the path from where its exicuted
but how can i modify so this so that after exicution of this script the control will go to cd <some path>

i mean suppose first /home/vidy>
after /home/vidya/fns/pd/r>

is it possible???
suggest some answer!!!!

This problem you're having is due to inheritance. When you run/execute your script, it inherits a copy of the current environment. Anything you do in the script affects your inherited environment but not that of your parent.

What you need to do is source your script instead of running it. When you source it, it runs under your current shell so changes that you make will be reflected in your environment when the script finishes executing.

Assuming your script is named test.sh, and you're in the directory where the script resides, source it as follows:
> . ./test.sh

If you do this, when execution is complete, you will be in whatever directory was specified by the "cd <some path>" command.

thanku very much this helped a lot.