The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Maintain full path of a script in a var when sourcing it from a different script mrbluegreen Shell Programming and Scripting 4 03-19-2008 06:31 PM
full path of .profile in unix dba UNIX for Dummies Questions & Answers 6 02-22-2008 02:12 AM
to find the file with full path surjyap Shell Programming and Scripting 5 01-18-2008 11:26 AM
Listing files with full path r_sethu UNIX for Dummies Questions & Answers 4 08-02-2007 06:35 PM
getting full path from relative path polypus Shell Programming and Scripting 4 03-25-2007 09:08 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-16-2005
Registered User
 

Join Date: Sep 2005
Location: Boston area
Posts: 2
Question Full path of executing script in ksh?

Hello all,

Here's the scenario:

I've got a script, let's call it script1. This script invokes another script, which we'll call set_env, via the dot "." command, like so:

File: [script1]
#!/bin/ksh
#
region_id=DEV
. set_env ${region_id}
and so on. Script set_env sets up an execution environment for the remainder of script1 according to the value of the parameter (region_id) passed.

My question/problem is:

Let us assume that set_env resides in the same directory as script1. How can I ensure that set_env will be found by the shell, when the containing directory is not in the PATH, and is not the PWD at the time script1 was invoked? In other words, how can script1 tell the shell to look for set_env in whatever directory script1 happens to reside?

I understand that ${_} is supposed to return the full pathname of the script being executed, but when I try to use that in script1, it fails to return anything meaningful.

Any hints will be very much appreciated. Thanks!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-16-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Code:
#!/bin/ksh
#
thisFile="$(whence ${0})"
thisDir="${thisFile%/*}"

region_id=DEV
. "${thisDir}"/set_env ${region_id}
Reply With Quote
  #3 (permalink)  
Old 09-19-2005
Registered User
 

Join Date: Sep 2005
Location: Boston area
Posts: 2
Thank you, that works just fine!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0