small script help

here is a small script:

if [ $# -lt 1 ]; then
echo please enter an argument
fi
if [ "$1" = "tom"; then
a=$1
echo $a
fi

here is my question. if the script name is j.sh and I run it : j.sh from shell prompt: without a parameter: it prints please enter an argument but if I go with . j.sh (current shell execution): it does not show that.

also if I go with an argument $ j.sh tom or $ . j.sh tom
the result is identical. however the next time I go with no argument, still I see the variable has a value tom with $ . j.sh tom. what makes the current shell execution keep the variable to value assigned even if on the next trun no argument is passed.

any suggestion would be highly appreciated.

thanks.

When you run a script like ./test.sh, then you fork a subshell and all execution is carried out in the context of that shell. Any environment variables that are set are done so in the env of the subshell. The environment of the current shell is not modified.
However, when you run a script like . ./test.sh, then you are changing the environment of the current shell and setting the various values as per your script. After the script is done, the values remain set as you are still running in the shell where the environment was modified.

Hope this is clear.