Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 142665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:58:22+00:00 2026-05-11T07:58:22+00:00

In a Windows command script, one can determine the directory path of the currently

  • 0

In a Windows command script, one can determine the directory path of the currently executing script using %~dp0. For example:

@echo Running from %~dp0 

What would be the equivalent in a Bash script?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:58:22+00:00Added an answer on May 11, 2026 at 7:58 am

    For the relative path (i.e. the direct equivalent of Windows’ %~dp0):

    MY_PATH="$(dirname -- "${BASH_SOURCE[0]}")" echo "$MY_PATH" 

    For the absolute, normalized path:

    MY_PATH="$(dirname -- "${BASH_SOURCE[0]}")"            # relative MY_PATH="$(cd -- "$MY_PATH" && pwd)"    # absolutized and normalized if [[ -z "$MY_PATH" ]] ; then   # error; for some reason, the path is not accessible   # to the script (e.g. permissions re-evaled after suid)   exit 1  # fail fi echo "$MY_PATH" 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a batch file script using Windows command and want to change
I've got a PHP script which I'm running from a command line (windows) that
On Windows XP, the following command in a script will prevent any power saving
I am running both maven inside the m2eclipse plugin, windows command line and my
Is there a better windows command line shell other than cmd which has better
For some reason the Windows command prompt is special in that you have to
Is there a Windows command that will output the size in bytes of a
Looking for a better Windows XP command-line interface. The Visual Studio Command Prompt isn't
I have a single windows shell command I'd like to run (via EXEC master..xp_cmdshell)
What's the best way (or tool) on the Windows (Vista) command line to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.