LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 02-18-2008, 11:04 PM   #1
jchambers
Member
 
Registered: Aug 2007
Location: California
Distribution: Debian
Posts: 127

Rep: Reputation: 15
Get the path of the shell script is running?


Hello all --

So I am running a .sh file

Code:
#!/bin/sh

cd /move/to/new/dir/
..
..
..
# can't use ./ any more
Is there a way to get the path of the .sh that is running?

Let me know if I need to reword the question.

jc
 
Old 02-18-2008, 11:10 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
You might need to reword the question. But you can 'OPWD=$(pwd)' and then cd and still refer to $OPWD, if that's what you're asking.
 
Old 02-18-2008, 11:15 PM   #3
jchambers
Member
 
Registered: Aug 2007
Location: California
Distribution: Debian
Posts: 127

Original Poster
Rep: Reputation: 15
Ah-ha!

Yes, sorry for the bad wording.
I had trouble expressing it...

That is exactly what I am looking for, thanks.

jc
 
Old 02-19-2008, 02:07 AM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I use this:
Code:
current="$(readlink -f $(dirname "$0"))"
previous="$(pwd)"
cd "$current"
ta0kira

Last edited by ta0kira; 02-19-2008 at 02:08 AM.
 
  


Reply



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
In which shell is the script running? indiancosmonaut Solaris / OpenSolaris 5 10-23-2007 12:13 AM
error in running the shell script bhandu Linux - Newbie 1 07-10-2007 01:16 AM
How can I determine the path of a shell script that I'm running right now ? basher400 Linux - General 7 10-25-2006 08:31 AM
a shell script edited, so all users can use it without having to type the whole path Goalswish Linux - Newbie 5 05-11-2006 10:37 AM
c/c++ running a shell script? thermalpants Programming 3 05-12-2002 11:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:19 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration