0

I want to set a directory path to variable using Windows Command Line without any user-interaction. So, like we do in Ubuntu OS:

my_path=$(pwd)

Here, output of pwd will get stored in my_path.

How to do this kind of task in Windows Command Line?

1
  • Just to clarify: In your example, pwd would not even be executed, and therefore no output would be stored anywhere. What your code does is to store the content of the variable pwd into the variable my_path. If you happen to be on a platform, where shell variables are case-insensitive, your code would be equivalent to my_path=$PWD, and since bash automatically sets the variable PWD to the working directory (after each cd, pushd or popd), your code does have the desired effect, though because of different reason than you think. Commented Sep 30, 2021 at 8:35

1 Answer 1

1

Actually, the more natural way in bash would have been

my_path=$PWD

Taking over this idea to Windows batch language, it would become

SET my_path=%CD%

The main difference is, that in Windows, my_path would end up in the environment automatically, while in bash, you would have to do this manually.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.