Terminal is closing on exit in ksh

hi

while executing the following script, my terminal window is getting closed if I enter a invalid option. I want the script should go back the the command prompt. how to do achive it. i execute the script as . ./test

#! /usr/bin/ksh

Printf " Type of Installer : \n\t\t 1. Whole Build \n\t\t 2. Partial Build "
printf " \n Enter the Option : "
read op
Option=0
if [ `echo "$op" | grep -c "[a-zA-Z]"` = "0" ]; then
    if [ "$op" -eq "1" ]; then
        Option=1
    elif  [ "$op" -eq "2" ]; then
        Option=2
    fi
fi

if [ "$Option" -eq "0" ]; then
    echo " Invalid Option "
    exit 255
fi

thanks in advance

The problem is the dot before ./test. The dot command causes your login shell to source the file instead of executing it in a separate process. Therefore the exit command exits your login shell.

To execute your script just type

./test

The problem is that you're sourcing the script, instead of running it. If sourced, the script is executed in the context of the current shell, instead of a different process, which is why the exit affects your terminal. Run it as

./test

instead.

Also, it's a good idea to change the name of the script, as test is both an executable (probably as /usr/bin/test) and a reserved word for most shells.

And a case construct looks much better:

#! /usr/bin/ksh

printf " Type of Installer : \n\t\t 1. Whole Build \n\t\t 2. Partial Build "
printf " \n Enter the Option : "
read op
Option=0

case "$op" in
  1)	Option=1
	;;
  2)	Option=2
	;;
  *)	echo " Invalid Option "
	exit 255
	;;
esac