Solved

find scripts directory location

Posted on 2006-06-09
4
223 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
ID: 16872858
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
ID: 16872937
Yes, that's it exactly, thanks!
0
 
LVL 6

Expert Comment

by:tone28
ID: 16872997
I would probably

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

pop(@parts);

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

Expert Comment

by:tone28
ID: 16873007
oops too late.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

830 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