I tried to customize windows command prompt with the following batch file.
@echo off
cls
:cmd
set /p "cmd=%cd%>"
%cmd%
goto cmd
So, when I open the batch file, it just takes my command into cmd
variable and executes it and again prompts for a new command.
But the following command echo %cd%
outputs only %cd%
Then I enabled delayedexpansion
and used echo !cd!
and got the desired output.
I think, because of the delayed expansion, cmd
variable now holds echo c:\Users\Sourav\Desktop
(am I correct?)
But I got confused when I tried to open the command prompt (not the batch file) and tried the following commands.
I thought, I will get c:\Users\Sourav\Desktop
but I got !cd!
. This contradicts my understanding of how echo !cd!
is working in first case.
Why am I getting different output in the second case?
Can anyone suggest any improvement to the batch file, so that I can get desired output just using echo %cd%
in first case?