pwd alias on Windows cmd












0















I want to create a fixed pwd alias like in this topic, but I want to keep all aliases in one file as in this answer by Argyll. Currently my file cmdAliases.cmd looks like this:



@echo off

doskey ls=dir
doskey pwd=echo ^%cd^%


Running pwd command now prints:



ECHO is on.


I believe the spaces in the command are the problem. Is there a way to fix it using only the cmdAliases.cmd file?










share|improve this question


















  • 3





    doskey pwd=cd. The cd command without parameters will just print the current working folder.

    – Stephan
    Nov 20 '18 at 10:33






  • 1





    Stephan's solution is the easiest one for command prompt and in a batch file. doskey pwd=echo ^%cd^% is the right syntax on pwd definition from within a command prompt window for echo %cd%. In a batch file must be used doskey pwd=echo %%cd%% to define execution of echo %cd% on typing pwd. Please note that echo %cd% as alias for pwd is in general not good in case of current directory contains in path an ampersand because of everything after & is interpreted by cmd.exe as additional command to execute. So best is definitely doskey pwd=cd.

    – Mofi
    Nov 20 '18 at 10:46













  • @Mofi, percent can't actually be escaped in an interactive CMD shell. We escape it in practice by disrupting the name matching, assuming no variable has "^" in its name. Thus in this case we want the "^" character on the right-hand side of the first "%" or the left-hand side of the second "%", or both for good measure. For example, "%^cd^%" has CMD look for a variable named "^cd^", and if none is defined it leaves the literal string "%^cd^%" in place. In the final parsing of the command line, the "^" escape character gets removed, leaving just "%cd%".

    – eryksun
    Nov 20 '18 at 23:07











  • @eryksun You are absolutely right and you explained it very good. I knew that already, but I did not want to write it here in a comment to avoid confusing original poster with such deep insight on how Windows command processor parses a line in command prompt window in comparison to parsing a command line in a batch file. However, the difference is explained in detail now by you with your comment. Thank you.

    – Mofi
    Nov 21 '18 at 9:21
















0















I want to create a fixed pwd alias like in this topic, but I want to keep all aliases in one file as in this answer by Argyll. Currently my file cmdAliases.cmd looks like this:



@echo off

doskey ls=dir
doskey pwd=echo ^%cd^%


Running pwd command now prints:



ECHO is on.


I believe the spaces in the command are the problem. Is there a way to fix it using only the cmdAliases.cmd file?










share|improve this question


















  • 3





    doskey pwd=cd. The cd command without parameters will just print the current working folder.

    – Stephan
    Nov 20 '18 at 10:33






  • 1





    Stephan's solution is the easiest one for command prompt and in a batch file. doskey pwd=echo ^%cd^% is the right syntax on pwd definition from within a command prompt window for echo %cd%. In a batch file must be used doskey pwd=echo %%cd%% to define execution of echo %cd% on typing pwd. Please note that echo %cd% as alias for pwd is in general not good in case of current directory contains in path an ampersand because of everything after & is interpreted by cmd.exe as additional command to execute. So best is definitely doskey pwd=cd.

    – Mofi
    Nov 20 '18 at 10:46













  • @Mofi, percent can't actually be escaped in an interactive CMD shell. We escape it in practice by disrupting the name matching, assuming no variable has "^" in its name. Thus in this case we want the "^" character on the right-hand side of the first "%" or the left-hand side of the second "%", or both for good measure. For example, "%^cd^%" has CMD look for a variable named "^cd^", and if none is defined it leaves the literal string "%^cd^%" in place. In the final parsing of the command line, the "^" escape character gets removed, leaving just "%cd%".

    – eryksun
    Nov 20 '18 at 23:07











  • @eryksun You are absolutely right and you explained it very good. I knew that already, but I did not want to write it here in a comment to avoid confusing original poster with such deep insight on how Windows command processor parses a line in command prompt window in comparison to parsing a command line in a batch file. However, the difference is explained in detail now by you with your comment. Thank you.

    – Mofi
    Nov 21 '18 at 9:21














0












0








0


1






I want to create a fixed pwd alias like in this topic, but I want to keep all aliases in one file as in this answer by Argyll. Currently my file cmdAliases.cmd looks like this:



@echo off

doskey ls=dir
doskey pwd=echo ^%cd^%


Running pwd command now prints:



ECHO is on.


I believe the spaces in the command are the problem. Is there a way to fix it using only the cmdAliases.cmd file?










share|improve this question














I want to create a fixed pwd alias like in this topic, but I want to keep all aliases in one file as in this answer by Argyll. Currently my file cmdAliases.cmd looks like this:



@echo off

doskey ls=dir
doskey pwd=echo ^%cd^%


Running pwd command now prints:



ECHO is on.


I believe the spaces in the command are the problem. Is there a way to fix it using only the cmdAliases.cmd file?







windows cmd






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 10:20









koman900koman900

807




807








  • 3





    doskey pwd=cd. The cd command without parameters will just print the current working folder.

    – Stephan
    Nov 20 '18 at 10:33






  • 1





    Stephan's solution is the easiest one for command prompt and in a batch file. doskey pwd=echo ^%cd^% is the right syntax on pwd definition from within a command prompt window for echo %cd%. In a batch file must be used doskey pwd=echo %%cd%% to define execution of echo %cd% on typing pwd. Please note that echo %cd% as alias for pwd is in general not good in case of current directory contains in path an ampersand because of everything after & is interpreted by cmd.exe as additional command to execute. So best is definitely doskey pwd=cd.

    – Mofi
    Nov 20 '18 at 10:46













  • @Mofi, percent can't actually be escaped in an interactive CMD shell. We escape it in practice by disrupting the name matching, assuming no variable has "^" in its name. Thus in this case we want the "^" character on the right-hand side of the first "%" or the left-hand side of the second "%", or both for good measure. For example, "%^cd^%" has CMD look for a variable named "^cd^", and if none is defined it leaves the literal string "%^cd^%" in place. In the final parsing of the command line, the "^" escape character gets removed, leaving just "%cd%".

    – eryksun
    Nov 20 '18 at 23:07











  • @eryksun You are absolutely right and you explained it very good. I knew that already, but I did not want to write it here in a comment to avoid confusing original poster with such deep insight on how Windows command processor parses a line in command prompt window in comparison to parsing a command line in a batch file. However, the difference is explained in detail now by you with your comment. Thank you.

    – Mofi
    Nov 21 '18 at 9:21














  • 3





    doskey pwd=cd. The cd command without parameters will just print the current working folder.

    – Stephan
    Nov 20 '18 at 10:33






  • 1





    Stephan's solution is the easiest one for command prompt and in a batch file. doskey pwd=echo ^%cd^% is the right syntax on pwd definition from within a command prompt window for echo %cd%. In a batch file must be used doskey pwd=echo %%cd%% to define execution of echo %cd% on typing pwd. Please note that echo %cd% as alias for pwd is in general not good in case of current directory contains in path an ampersand because of everything after & is interpreted by cmd.exe as additional command to execute. So best is definitely doskey pwd=cd.

    – Mofi
    Nov 20 '18 at 10:46













  • @Mofi, percent can't actually be escaped in an interactive CMD shell. We escape it in practice by disrupting the name matching, assuming no variable has "^" in its name. Thus in this case we want the "^" character on the right-hand side of the first "%" or the left-hand side of the second "%", or both for good measure. For example, "%^cd^%" has CMD look for a variable named "^cd^", and if none is defined it leaves the literal string "%^cd^%" in place. In the final parsing of the command line, the "^" escape character gets removed, leaving just "%cd%".

    – eryksun
    Nov 20 '18 at 23:07











  • @eryksun You are absolutely right and you explained it very good. I knew that already, but I did not want to write it here in a comment to avoid confusing original poster with such deep insight on how Windows command processor parses a line in command prompt window in comparison to parsing a command line in a batch file. However, the difference is explained in detail now by you with your comment. Thank you.

    – Mofi
    Nov 21 '18 at 9:21








3




3





doskey pwd=cd. The cd command without parameters will just print the current working folder.

– Stephan
Nov 20 '18 at 10:33





doskey pwd=cd. The cd command without parameters will just print the current working folder.

– Stephan
Nov 20 '18 at 10:33




1




1





Stephan's solution is the easiest one for command prompt and in a batch file. doskey pwd=echo ^%cd^% is the right syntax on pwd definition from within a command prompt window for echo %cd%. In a batch file must be used doskey pwd=echo %%cd%% to define execution of echo %cd% on typing pwd. Please note that echo %cd% as alias for pwd is in general not good in case of current directory contains in path an ampersand because of everything after & is interpreted by cmd.exe as additional command to execute. So best is definitely doskey pwd=cd.

– Mofi
Nov 20 '18 at 10:46







Stephan's solution is the easiest one for command prompt and in a batch file. doskey pwd=echo ^%cd^% is the right syntax on pwd definition from within a command prompt window for echo %cd%. In a batch file must be used doskey pwd=echo %%cd%% to define execution of echo %cd% on typing pwd. Please note that echo %cd% as alias for pwd is in general not good in case of current directory contains in path an ampersand because of everything after & is interpreted by cmd.exe as additional command to execute. So best is definitely doskey pwd=cd.

– Mofi
Nov 20 '18 at 10:46















@Mofi, percent can't actually be escaped in an interactive CMD shell. We escape it in practice by disrupting the name matching, assuming no variable has "^" in its name. Thus in this case we want the "^" character on the right-hand side of the first "%" or the left-hand side of the second "%", or both for good measure. For example, "%^cd^%" has CMD look for a variable named "^cd^", and if none is defined it leaves the literal string "%^cd^%" in place. In the final parsing of the command line, the "^" escape character gets removed, leaving just "%cd%".

– eryksun
Nov 20 '18 at 23:07





@Mofi, percent can't actually be escaped in an interactive CMD shell. We escape it in practice by disrupting the name matching, assuming no variable has "^" in its name. Thus in this case we want the "^" character on the right-hand side of the first "%" or the left-hand side of the second "%", or both for good measure. For example, "%^cd^%" has CMD look for a variable named "^cd^", and if none is defined it leaves the literal string "%^cd^%" in place. In the final parsing of the command line, the "^" escape character gets removed, leaving just "%cd%".

– eryksun
Nov 20 '18 at 23:07













@eryksun You are absolutely right and you explained it very good. I knew that already, but I did not want to write it here in a comment to avoid confusing original poster with such deep insight on how Windows command processor parses a line in command prompt window in comparison to parsing a command line in a batch file. However, the difference is explained in detail now by you with your comment. Thank you.

– Mofi
Nov 21 '18 at 9:21





@eryksun You are absolutely right and you explained it very good. I knew that already, but I did not want to write it here in a comment to avoid confusing original poster with such deep insight on how Windows command processor parses a line in command prompt window in comparison to parsing a command line in a batch file. However, the difference is explained in detail now by you with your comment. Thank you.

– Mofi
Nov 21 '18 at 9:21












1 Answer
1






active

oldest

votes


















2














The links you provided show how to do it.



I have my doskey macros in a file aliases.txt in my folder %USERPROFILE%



11:24:16 C:UsersLotPings________________________________________
> type Aliases.txt
~=CD /D "C:UsersLotPings"
=CD
-=CD ..
Alias=Doskey $*
Aliases=Doskey /MACROS:ALL


And an autorun entry which loads this file



> reg query "HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor" /v autorun
HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor
autorun REG_SZ Doskey /MacroFile="C:UsersLotPingsAliases.txt"


To generate this Autorun automatically copy the following lines into cmd line or a batch file



Set "Key=HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor"
Set "Val=Autorun"
Set "Typ=REG_SZ"
Set "Dat=Doskey /Macrofile="%USERPROFILE%Aliases.txt""
reg add "%Key%" /v %Val% /t %Typ% /d "%Dat%" /f





share|improve this answer



















  • 1





    Note that the C runtime system function oddly runs commands via cmd /c without the /d option that skips the autorun command. It also runs again needlessly for a subshell, which inherits the parent shell's environment and console (i.e. the conhost.exe host process, where doskey aliases are defined and evaluated) and thus usually doesn't need configuration. To avoid this, we can set the autorun command to a script that exits if %CMDCMDLINE% indicates a non-interactive shell or if it was already run, as indicated by setting an environment variable (e.g. set "CMD_AUTORUN=%0").

    – eryksun
    Nov 20 '18 at 22:54











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390827%2fpwd-alias-on-windows-cmd%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














The links you provided show how to do it.



I have my doskey macros in a file aliases.txt in my folder %USERPROFILE%



11:24:16 C:UsersLotPings________________________________________
> type Aliases.txt
~=CD /D "C:UsersLotPings"
=CD
-=CD ..
Alias=Doskey $*
Aliases=Doskey /MACROS:ALL


And an autorun entry which loads this file



> reg query "HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor" /v autorun
HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor
autorun REG_SZ Doskey /MacroFile="C:UsersLotPingsAliases.txt"


To generate this Autorun automatically copy the following lines into cmd line or a batch file



Set "Key=HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor"
Set "Val=Autorun"
Set "Typ=REG_SZ"
Set "Dat=Doskey /Macrofile="%USERPROFILE%Aliases.txt""
reg add "%Key%" /v %Val% /t %Typ% /d "%Dat%" /f





share|improve this answer



















  • 1





    Note that the C runtime system function oddly runs commands via cmd /c without the /d option that skips the autorun command. It also runs again needlessly for a subshell, which inherits the parent shell's environment and console (i.e. the conhost.exe host process, where doskey aliases are defined and evaluated) and thus usually doesn't need configuration. To avoid this, we can set the autorun command to a script that exits if %CMDCMDLINE% indicates a non-interactive shell or if it was already run, as indicated by setting an environment variable (e.g. set "CMD_AUTORUN=%0").

    – eryksun
    Nov 20 '18 at 22:54
















2














The links you provided show how to do it.



I have my doskey macros in a file aliases.txt in my folder %USERPROFILE%



11:24:16 C:UsersLotPings________________________________________
> type Aliases.txt
~=CD /D "C:UsersLotPings"
=CD
-=CD ..
Alias=Doskey $*
Aliases=Doskey /MACROS:ALL


And an autorun entry which loads this file



> reg query "HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor" /v autorun
HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor
autorun REG_SZ Doskey /MacroFile="C:UsersLotPingsAliases.txt"


To generate this Autorun automatically copy the following lines into cmd line or a batch file



Set "Key=HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor"
Set "Val=Autorun"
Set "Typ=REG_SZ"
Set "Dat=Doskey /Macrofile="%USERPROFILE%Aliases.txt""
reg add "%Key%" /v %Val% /t %Typ% /d "%Dat%" /f





share|improve this answer



















  • 1





    Note that the C runtime system function oddly runs commands via cmd /c without the /d option that skips the autorun command. It also runs again needlessly for a subshell, which inherits the parent shell's environment and console (i.e. the conhost.exe host process, where doskey aliases are defined and evaluated) and thus usually doesn't need configuration. To avoid this, we can set the autorun command to a script that exits if %CMDCMDLINE% indicates a non-interactive shell or if it was already run, as indicated by setting an environment variable (e.g. set "CMD_AUTORUN=%0").

    – eryksun
    Nov 20 '18 at 22:54














2












2








2







The links you provided show how to do it.



I have my doskey macros in a file aliases.txt in my folder %USERPROFILE%



11:24:16 C:UsersLotPings________________________________________
> type Aliases.txt
~=CD /D "C:UsersLotPings"
=CD
-=CD ..
Alias=Doskey $*
Aliases=Doskey /MACROS:ALL


And an autorun entry which loads this file



> reg query "HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor" /v autorun
HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor
autorun REG_SZ Doskey /MacroFile="C:UsersLotPingsAliases.txt"


To generate this Autorun automatically copy the following lines into cmd line or a batch file



Set "Key=HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor"
Set "Val=Autorun"
Set "Typ=REG_SZ"
Set "Dat=Doskey /Macrofile="%USERPROFILE%Aliases.txt""
reg add "%Key%" /v %Val% /t %Typ% /d "%Dat%" /f





share|improve this answer













The links you provided show how to do it.



I have my doskey macros in a file aliases.txt in my folder %USERPROFILE%



11:24:16 C:UsersLotPings________________________________________
> type Aliases.txt
~=CD /D "C:UsersLotPings"
=CD
-=CD ..
Alias=Doskey $*
Aliases=Doskey /MACROS:ALL


And an autorun entry which loads this file



> reg query "HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor" /v autorun
HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor
autorun REG_SZ Doskey /MacroFile="C:UsersLotPingsAliases.txt"


To generate this Autorun automatically copy the following lines into cmd line or a batch file



Set "Key=HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor"
Set "Val=Autorun"
Set "Typ=REG_SZ"
Set "Dat=Doskey /Macrofile="%USERPROFILE%Aliases.txt""
reg add "%Key%" /v %Val% /t %Typ% /d "%Dat%" /f






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 10:43









LotPingsLotPings

19.1k61532




19.1k61532








  • 1





    Note that the C runtime system function oddly runs commands via cmd /c without the /d option that skips the autorun command. It also runs again needlessly for a subshell, which inherits the parent shell's environment and console (i.e. the conhost.exe host process, where doskey aliases are defined and evaluated) and thus usually doesn't need configuration. To avoid this, we can set the autorun command to a script that exits if %CMDCMDLINE% indicates a non-interactive shell or if it was already run, as indicated by setting an environment variable (e.g. set "CMD_AUTORUN=%0").

    – eryksun
    Nov 20 '18 at 22:54














  • 1





    Note that the C runtime system function oddly runs commands via cmd /c without the /d option that skips the autorun command. It also runs again needlessly for a subshell, which inherits the parent shell's environment and console (i.e. the conhost.exe host process, where doskey aliases are defined and evaluated) and thus usually doesn't need configuration. To avoid this, we can set the autorun command to a script that exits if %CMDCMDLINE% indicates a non-interactive shell or if it was already run, as indicated by setting an environment variable (e.g. set "CMD_AUTORUN=%0").

    – eryksun
    Nov 20 '18 at 22:54








1




1





Note that the C runtime system function oddly runs commands via cmd /c without the /d option that skips the autorun command. It also runs again needlessly for a subshell, which inherits the parent shell's environment and console (i.e. the conhost.exe host process, where doskey aliases are defined and evaluated) and thus usually doesn't need configuration. To avoid this, we can set the autorun command to a script that exits if %CMDCMDLINE% indicates a non-interactive shell or if it was already run, as indicated by setting an environment variable (e.g. set "CMD_AUTORUN=%0").

– eryksun
Nov 20 '18 at 22:54





Note that the C runtime system function oddly runs commands via cmd /c without the /d option that skips the autorun command. It also runs again needlessly for a subshell, which inherits the parent shell's environment and console (i.e. the conhost.exe host process, where doskey aliases are defined and evaluated) and thus usually doesn't need configuration. To avoid this, we can set the autorun command to a script that exits if %CMDCMDLINE% indicates a non-interactive shell or if it was already run, as indicated by setting an environment variable (e.g. set "CMD_AUTORUN=%0").

– eryksun
Nov 20 '18 at 22:54




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390827%2fpwd-alias-on-windows-cmd%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?