LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-09-2005, 02:03 PM   #1
cxc
LQ Newbie
 
Registered: Sep 2005
Posts: 1

Rep: Reputation: 0
how to determine script path


Hi folks,

Does anyone know how I can get my shell script to determine the path where it resides? For example, if my shell script resides in /usr/bin/, I would like it to print out "/usr/bin".

Thanks

Chris
 
Old 09-09-2005, 02:07 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,500

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
(cd $(dirname $0);pwd)
 
Old 09-10-2005, 08:32 AM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
Originally posted by jlliagre
(cd $(dirname $0);pwd)
Won't this only work if the script is called with a full path?
 
Old 09-10-2005, 08:36 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,500

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
No, it works in that case too.
It's easy to check by ourself, by the way.

Last edited by jlliagre; 09-10-2005 at 08:37 AM.
 
  


Reply


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
shell script to read ps -e output and determine process double processes. dr_zayus69 Programming 1 09-21-2005 05:37 PM
Need help with finding path in bash script ylikone Linux - Software 1 08-02-2005 10:47 AM
Does anyone know of a bash script that will determine if RPM exists on a system? jimwelc Linux - Software 3 12-28-2004 03:01 PM
Script to determine last disconnection colabus Linux - Newbie 4 09-24-2004 12:42 AM
Which script is corrupting my path? robertmarkbram Linux - Software 1 05-03-2004 04:40 AM


All times are GMT -5. The time now is 11:08 AM.

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