Solved

find scripts directory location

Posted on 2006-06-09
4
195 Views
Last Modified: 2012-05-05

If $0 gives the location of the script you are running, how can I just get the directory where the script is located?

CWD; doesn't work the I want, since if I execute a script located on a network drive from the commandline on my local PC, the working directory would be whatever directory I'm in at my shell.


0
Comment
Question by:Marketing_Insists
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
GnarOlak earned 300 total points
Comment Utility
If what you are asking is how to extract from $0, which has both a path and the name of the script, just the directory then you can use File::Basename thus:

use File::Basename;

$script = basename ($0);
$dir = dirname($0);

print "$script was run from $dir\n";
__END__

If that isn't what you need then please elaborate.

0
 

Author Comment

by:Marketing_Insists
Comment Utility
Yes, that's it exactly, thanks!
0
 
LVL 6

Expert Comment

by:tone28
Comment Utility
I would probably

my @parts = split('\\\\',$0);

pop(@parts);

print join "\\",@parts;
0
 
LVL 6

Expert Comment

by:tone28
Comment Utility
oops too late.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now