using alias parameters in window command prompt

Posted by freshWoWer on Stack Overflow See other posts from Stack Overflow or by freshWoWer
Published on 2010-12-15T20:57:06Z Indexed on 2011/01/17 21:53 UTC
Read the original article Hit count: 393

Filed under:
|
|
|

Source:http://jpsoft.com/help/index.htm?alias.htm

Aliases can use command line parameters or parameters like those in batch files. The command line parameters are numbered from %0 to %511. (%0 contains the alias name.)

For example, the following alias will change directories, perform a command, and return to the original directory:

alias in pushd %1 & %2$ & popd

when i run the above, my command prompt gives error saying

%1 * Unable to read value of alias * '%2' is not recognized as an internal or external command, operable program or batch file. 'popd`' is not recognized as an internal or external command, operable program or batch file.

if you use double quote instead, alias in "pushd %1 & dir & popd" it doesn't interprets the %1 when you execute the alias

C:\abc\def>alias Dumping all defined aliases for CMD.EXE. in =pushd %1 & dir & popd

alias def wont work

---------EDIT------------ let me try some sample output with a simple echo alias

D:\abc\def>alias /?

Usage: ALIAS [-v] [-p programName] [-f filespec] [ ]

         [-v] means verbose output.

         [-d] means delete aliases.

         [-p programName] specifies which image file name these alias

                          definitions are for.  Default is CMD.EXE

         [-f filespec] specifies a file which contains the alises.

C:\Office\dev15>alias out 'echo %1'

%1' * Unable to read value of alias *

C:\Office\dev15>alias out backtick echo %1 backtick

%1` * Unable to read value of alias *

C:\Office\dev15>alias out "echo %1"

C:\Office\dev15>alias

Dumping all defined aliases for CMD.EXE.

out             =echo %1

C:\Office\dev15>out abc

%1

C:\Office\dev15>alias out echo %1

%1 * Unable to read value of alias *

C:\Office\dev15>out abc

ECHO is on.

Problem is, both single quote and back tick produces error, while double quote wont treat %1 as variable parameter

© Stack Overflow or respective owner

Related posts about cmd

Related posts about dos