LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-21-2008, 03:24 AM   #1
jiju.jacob
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Rep: Reputation: 0
Getting location of the script which is currently being executed


Hi,

I have a shell script named a.sh inside /home/root directory and I have to run this script from the /tmp directory.

I issue the command as

linux-7vps: /tmp # ./home/root/a.sh

Now inside a.sh, I would like to get the path where this script a.sh resides without opting for a search.

Can I get the location of the script ?

Please let me know how to do it ?

Linux Flavor : RHEL 4/ RHEL 5

Thanks in Advance,
Jiju
 
Old 07-21-2008, 03:27 AM   #2
odcheck
Member
 
Registered: Aug 2006
Distribution: Fedora, CentOS, RHEL, Debian
Posts: 978

Rep: Reputation: 30
pwd would be a command.
But what is /home/root ?

maybe it would help to know what the script finaly should do at all?
 
Old 07-21-2008, 03:37 AM   #3
jiju.jacob
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by odcheck View Post
pwd would be a command.
But what is /home/root ?

maybe it would help to know what the script finaly should do at all?

/home/root is the home directory for the root user.
This tiny script is intended to be a part of larger script. The function of the tiny script is to write the directory name on which resides to a file as soon as it is executed. Another Process will then read the path of the script from this file and use it for other purposes.
 
Old 07-21-2008, 03:42 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You can try either
Code:
dirname `which $0`
or
Code:
readlink -f $0
you can also read the insights in this thread about the same topic.
 
Old 07-21-2008, 05:48 AM   #5
jiju.jacob
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks a lot colucix.
 
  


Reply

Tags
directory, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script executed inside another script dont make changes potraike Linux - Newbie 4 03-05-2008 05:27 AM
Script is executed when user logout karthi26 Linux - Newbie 10 07-12-2007 07:26 AM
zsh return 0 if script sourced not executed cs-cam Linux - General 2 08-12-2006 11:41 AM
hotplug script executed 3 times Borelian Linux - Software 1 06-28-2004 11:46 PM
Simple script to be executed on startup. Korff Linux - General 2 06-03-2003 09:25 PM


All times are GMT -5. The time now is 11:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration