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?
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.
pwdwould not even be executed, and therefore no output would be stored anywhere. What your code does is to store the content of the variablepwdinto the variablemy_path. If you happen to be on a platform, where shell variables are case-insensitive, your code would be equivalent tomy_path=$PWD, and since bash automatically sets the variablePWDto the working directory (after eachcd,pushdorpopd), your code does have the desired effect, though because of different reason than you think.