[Solved] Korn Shell execution | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

[Solved] Korn Shell execution

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-05-2013
kumarjt kumarjt is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 October 2013, 5:16 AM EDT
Posts: 41
Thanks: 3
Thanked 1 Time in 1 Post
[Solved] Korn Shell execution

There are two Korn Shell scripts :
script_1.ksh ( located in /home/dir1 )
script_2.ksh ( located in /home/dir2 )
Content of script_2.ksh is

Code:
#!/usr/bin/ksh
echo "Hello world.."

The script_2.ksh is called from within script_1.ksh using the following command :
Code:
./home/dir2/script_2.ksh

but the "Hello world.." is not printed .
Error shown is :./home/dir2/script_2.ksh: not found

But , if a SPACE is added in between the dot and forward slash for command , the script works fine.
ie.,

Code:
. /home/dir2/script_2.ksh

Why is it so ?
How does the shell interpret this command , but aborts with the previous one ?
Please explain.
Thanks
Kumarjit
OS : Linux 2.6x

Last edited by vbe; 07-05-2013 at 08:14 AM.. Reason: extra code tags...
Sponsored Links
    #2  
Old 07-05-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 27 July 2014, 5:28 AM EDT
Location: Switzerland - GE
Posts: 5,609
Thanks: 151
Thanked 387 Times in 364 Posts
Have you tried:

Code:
/home/dir2/script_2.ksh

Does it work?
Why?

Quote:
Error shown is :./home/dir2/script_2.ksh: not found
Which is certainly true...
Sponsored Links
    #3  
Old 07-05-2013
kumarjt kumarjt is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 October 2013, 5:16 AM EDT
Posts: 41
Thanks: 3
Thanked 1 Time in 1 Post
/home/dir2/script_2.ksh works good .
But the actual problem is something different , in place of script_2.ksh , what I have is a global_variable.cfg file which basically initializes values of a set of environment variables.

sample command in the global_variable.cfg file is like :
TEST_NAME="KUMARJIT"; export TEST_NAME

If I use /home/dir2/global_variable.cfg and try to access the value of TEST_NAME in my script , I am not able to see the value , whereas ,if I use . /home/dir2/global_variable.cfg ( please take a note of space between the dot and forward slash ) , I am able to access the value of the TEST_NAME variable .

Why ?
    #4  
Old 07-05-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 27 July 2014, 5:28 AM EDT
Location: Switzerland - GE
Posts: 5,609
Thanks: 151
Thanked 387 Times in 364 Posts
Ah but now you are not talking of the same thing...
Here Dot is sourcing your environment...
This is the way to load environmnet that has to be set before a script using them can be run when you dont include the needed variable initialization in the script itself...
Sponsored Links
    #5  
Old 07-05-2013
techy1 techy1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 24 July 2014, 12:19 PM EDT
Posts: 50
Thanks: 6
Thanked 5 Times in 5 Posts
to add to vbe.

using the "./" is telling the script to look from the current path to execute script.
The Following User Says Thank You to techy1 For This Useful Post:
kumarjt (07-08-2013)
Sponsored Links
    #6  
Old 07-05-2013
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 27 July 2014, 6:22 PM EDT
Location: /dev/ph
Posts: 4,772
Thanks: 59
Thanked 423 Times in 392 Posts
To include variables defined in a configuration file, you need to source the configuration file. In ksh, you can do it one of two ways

Code:
source /path/to/my/configuration/file

or, and this is the more common way

Code:
. /path/to/my/configuration/file

Note the space between the period and the filepath.
The Following User Says Thank You to fpmurphy For This Useful Post:
kumarjt (07-08-2013)
Sponsored Links
    #7  
Old 07-08-2013
kumarjt kumarjt is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 October 2013, 5:16 AM EDT
Posts: 41
Thanks: 3
Thanked 1 Time in 1 Post
@vbe : It didnt understand the following :
Here Dot is sourcing your environment...

To add to my surprises let me put forward a wierd scenario .
When I am in any folder OTHER THAN THE ONE WHERE THIS global_variable.cfg file resides ,

I can sucessfully execute the following statement and set the environment variables using the file .

Code:
. /<absolute path name>/global_variable.cfg

But when I try the following , the Unix throws an error indicating that the file cannot be found.

Code:
  cd <absolute path name>
  . /global_variable.cfg

Please note , I have included a space between the period and slash everytime , but once I succed , and once I fail .

Why ????

Thanks
Kumarjit.

Last edited by vbe; 07-08-2013 at 08:16 AM.. Reason: missing a code bracket...
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[Solved] How to refer more than 9 command line inputs for a scripts in korn shell? pat_pramod Shell Programming and Scripting 15 12-06-2013 05:37 AM
[Solved] Issue with using for loop as for in {2..6} in korn shell 100bees Shell Programming and Scripting 4 07-02-2013 06:26 AM
[solved]Korn, disabling * substitution Wreckoning UNIX for Dummies Questions & Answers 3 12-15-2012 12:20 AM
Korn Shell Script help required during execution... marconi Shell Programming and Scripting 1 07-21-2008 02:28 PM
korn shellscript execution context - exit statement richgi UNIX for Dummies Questions & Answers 3 03-29-2005 11:48 PM



All times are GMT -4. The time now is 10:23 AM.