What is the significance of . / ?

Many scripts are executed in the following way.

. /scriptname

Even when the file does not have execute permission, it can be executed this way. How does this work?

In this case, scriptname is passed as an argument to the current shell i.e. you are asking the current shell to execute it.

When you do ./scriptname, you are executing scriptname in a subshell within the current shell.

I have script named test.ksh under /tmp directory.

ls -l test.ksh
-rwx------   1 enaggan  inmalogin      30 Jul 16 11:59 test.ksh

I have execute permisson on it.

Case 1:
I am trying to run the above script by,
cd /tmp
test.ksh
ksh: test.ksh: not found

This doesnot work as we have not added the path /tmp to the PATH varible.

Case 2:
I am trying to run the above script by,
cd /tmp
./test.ksh
Hello World

To run a script that is not present in any of the directories in the PATH variable,we have to explicitly state path of the script.
i.e Either the full path or relative path.
Eg: /tmp/test.ksh or ./test.ksh

Case 3:

In case of we don't execute permisson on the script,
We can pass the name of the script as an argument to ksh.

Example:
ksh test.ksh
Hello World

 cat /tmp/test.ksh
   #!/bin/ksh
   echo "Hello World"

Hope this clarifies.

Thanks
Nagarajan Ganesan

Case 3 was what I was looking at. Thanks Nagarajan and Thanks Vino.

Welcoming more discussions on this topic...

well, basically when you source a file like this you are running it in the
context of the current shell.
simply put, if you do
. script you are not running it, you are including it line by line, sort of.
So if you do it from the command line it's as if you have typed the script in manually so all variables, functions etc. will remain once the process is over.

it is generally a way of importing variables functions etc into the current environment or context whatever you like to call it.

a script run normally will do it's own thing without affecting the current
script or environment.

if you get what i mean.

@bigearsbilly:

I can relate to what you are trying to explain, as I've applied the same practically without knowing what is actually being done. Its very clear. Thanks for your explanation!

super!

no problem-o.