The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Listing files with full path r_sethu UNIX for Dummies Questions & Answers 5 06-15-2009 02:56 AM
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 10:31 PM
full path of .profile in unix dba UNIX for Dummies Questions & Answers 6 02-22-2008 06:12 AM
to find the file with full path surjyap Shell Programming and Scripting 5 01-18-2008 03:26 PM
getting full path from relative path polypus Shell Programming and Scripting 4 03-25-2007 12:08 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-16-2005
BriceBu BriceBu is offline
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!
  #2 (permalink)  
Old 09-16-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

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

region_id=DEV
. "${thisDir}"/set_env ${region_id}
  #3 (permalink)  
Old 09-19-2005
BriceBu BriceBu is offline
Registered User
  
 

Join Date: Sep 2005
Location: Boston area
Posts: 2
Thank you, that works just fine!
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0