Skip to content
Advertisement

How do I write this in a batch file

I am trying to convert a shell script into a batch file but I am stuck at this place.

I am not quite sure how to convert this line into my batch file.

$(echo $(cd $(dirname $0)/../..; pwd))

I tried

echo %(cd %(dirname %0%)%/.../..; pwd)%

but I am not sure if I am right!

Advertisement

Answer

You can’t do command chaining like this in Batch. If I see that correctly, you want to get the absolute path of the directory two levels above the directory of the currently executed script. You might do this:

@ECHO OFF
CD %~dp0....
ECHO %CD%

Which changes the current directory. To avoid that, use:

@ECHO OFF
PUSHD %~dp0....
ECHO %CD%
POPD
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement