Want to understand the meaning of the following line

HI All
Please find the code below from a script called test.sh

echo "Hello World"
. test_common.lib
get_info

in the file test_common.lib i have the following contents

get_info()
{
c_cnt=0;
cm="";
echo "Inside get_info"
}

when i run the script test.sh

i get a error message

test.sh: line 3: get_info: command not found

First of all i would like to know how this line behaves
"test_common.lib"

Regards
Dhanamurthy

. test_common.lib

Executes test_common.lib in the same shell so that you can access variables and functions defined in it.

What you are doing is correct. Check whether test_common.lib in test.sh directory contains definition of that function?

What shell are you using for this? I tried this with sh, ksh and bash, and it worked with all three. I had to make one modification though:

#!/usr/bin/bash

echo "Hello World"
. ./test_common.lib
get_info

Without the "./" it was giving a "./test.sh: test_common.lib: not found" error under sh and ksh.

As for the explanation of how the ". test_common.lib" line works, here's how:

When you run . test_common.lib, or in my case . ./test_common.lib, the statements in the test_common.lib file are processed inside the calling shell itself, unlike when you just run ./test_common.lib (this forks a seperate process). Because the calling shell processes these, any statements such as variable definitions, function definitions, etc are stored in the calling shell and are available for later use.

Hope that was clear (though it probably isn't).

The line
. test_common.lib though executes successfully in the script, the get_info function is not able to execute as the definition for get_info is not made available.
When i ran . ./test_common.lib.

It's proceeding further by calling the function.
I am using bash scripting.

Not sure of how this line behaves.

Thanks for your inputs.

REgards
Dhanamurthy

Works fine if "." is included in the PATH variable, for example :

PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:.

Jean-Pierre.

Yes, I know, but I never have '.' in my path...