Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there an environment variable in Windows 7 that is set to the name of the currently running script when I run a script?

I'm looking for the Windows equivalent of the Linux variable $0.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Some more info...

%0 is a bit quirky. Depending on how you call the script you will/will not get PATH and extension.

To always get the fully qualified script name this should work %~f0

To learn about how %~f0 works ... at a command prompt enter for /?

FYI... just about every batch language term responds to /?

e.g.

if /? call /? del /? rem /? cmd /? (a lot of interesting info for this one)

For a list of batch language terms, at the command prompt enter just help

share|improve this answer
    
Even better. Thanks so much. I knew about /? I just didn't know where to get info about expansion/substitution with that %~ syntax. –  sirlancelot Apr 16 '10 at 22:11

Yes, its %0

When I tried to post the above short answer I got

Oops! Your answer couldn't be submitted because:

   * body is too short

Now it should be long enough :-)

share|improve this answer

%0 is what you are looking for.

share|improve this answer
    
I should've guessed! Thanks for the answer. Just what I needed. –  sirlancelot Apr 16 '10 at 19:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.