在窗口命令提示符中使用别名参数

发布于 2024-10-08 11:17:58 字数 1693 浏览 0 评论 0原文

来源:http://jpsoft.com/help/index.htm?alias.htm

别名可以使用命令行 参数或类似的参数 批处理文件。命令行 参数编号从 %0 到 %511。 (%0 包含别名。)

<块引用> <块引用>

例如,以下别名将 更改目录,执行命令, 并返回原目录:

pushd %1 & 中的别名%2$ &弹出窗口

当我运行上面的命令时,我的命令提示符给出错误,说

%1 * 无法读取别名的值 * “%2”未被识别为内部或外部命令, 可运行的程序或批处理文件。 “popd”不被识别为内部或外部命令, 可运行的程序或批处理文件。

如果您使用双引号,请使用“pushd %1 & dir & popd”中的别名 时,它不会解释 %1

当您执行别名C:\abc\def>alias 转储 CMD.EXE 的所有已定义别名。 在 =pushd %1 &目录& popd

别名 def 不起作用

---------编辑------------ 让我尝试使用简单的 echo 别名

D:\abc\def>alias /?

的一些示例输出用法: ALIAS [-v] [-p 程序名] [-f 文件规范] [ ]

         [-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' * 无法读取别名值 *

C:\Office\dev15>别名反引号 echo %1 反引号

%1` * 无法读取别名的值 *

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

C:\Office \dev15>alias

转储 CMD.EXE 的所有已定义别名。

out             =echo %1

C:\Office\dev15>out abc

%1

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

%1 * 无法读取别名值 *

C:\Office\dev15>out abc

ECHO已开启。

问题是, 单引号和反引号都会产生错误, 而双引号不会将 %1 视为变量参数 也尝试过不带任何引号。 还是不行

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
also tried with none of the quotes.
still wouldnot work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋叶绚丽 2024-10-15 11:17:58

好的,尝试一下(使用复制和粘贴):

   alias dtxt = `pushd %1 & dir %2$ & popd`

这会将别名“dtxt”设置为以下命令:

   pushd %1
   dir %2
   popd

特别注意别名定义周围的单引号 (`)。该键位于 ISO(英国)和 ANSI(美国)键盘的左上角键上。

您需要提供两个参数,%1%2< /strong> 执行 dtxt 时 - 目标路径名和 DIR 命令的参数,如下例所示:

   dtxt c:\temp *.txt

简而言之,PUSHD 将当前工作目录名称推送到后进先出堆栈并将目录更改为 c:\temp。

然后,DIR 命令以 %2 作为参数执行 - 在本例中为 >'*.txt'。

最后,POPD通过将其从堆栈中弹出来恢复以前的工作目录。

仅供参考,这相当于以下标准 DOS 命令:

   dir c:\temp\*.txt

标准 DOS 中的以下命令也可以正常工作:

   pushd & dir *.txt & popd

但显然,“dtxt”更短并且可以节省击键次数!

Okay, try this (use copy and paste):

   alias dtxt = `pushd %1 & dir %2$ & popd`

This sets the alias 'dtxt' to the following commands:

   pushd %1
   dir %2
   popd

Pay particular attention to the inverted single quotes (`) around the alias definition. This is found on the top-left key on the ISO (UK) and ANSI (US) keyboards.

You will need to supply two parameters, %1 and %2 when executing dtxt - a target pathname, and a parameter for the DIR command as in the following examples:

   dtxt c:\temp *.txt

In a nutshell, PUSHD pushes the current working directory name onto a LIFO stack and changes directory to c:\temp.

The DIR command then executes with %2 as it's parameter - in this case '*.txt'.

Finally, POPD restores the previous working directory by popping it off the stack.

FYI, this is equivalent to the following standard DOS command:

   dir c:\temp\*.txt

The following command in standard DOS will also work fine:

   pushd & dir *.txt & popd

But obviously, 'dtxt' is shorter and saves keystrokes!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文