1

有没有办法让我的 Windows 7 系统上的所有 DOS shell 都有这个命令别名?

doskey h=doskey /history

这是否可能,就像 Bash shell 可以加载 .bash_profile 一样?我正在寻找不需要 PowerShell 的答案。

4

3 回答 3

4

好吧,DOS在这里并不是一个正确的词。在当前版本的 Windows 中,您拥有 CMD.exe shell,它具有许多与 DOS 相同的命令(dir、copy 等)。您可能还拥有 PowerShell。在 PowerShell 中,很容易将别名配置为始终可用。创建一个名为$home\Documents\WindowsPowerShell\profile.ps1并创建别名的文件,如下所示:

New-Alias h Get-History # Don't execute as it already exists

但是,PowerShell 已经为您创建了这个特定的别名。只需打开 PowerShell,执行一些命令,然后执行h.

至于 CMD.exe,这篇文描述了如何配置 CMD.exe 来做同样的事情。

于 2012-11-28T00:25:00.707 回答
1

简而言之:不。命令处理器(cmd.exe 和 command.com)不支持别名,因为您从 bash 和其他 shell 中知道它们。

更长的答案:您可以通过制作巧妙的批处理文件来创建一个“假”别名,这些文件采用参数(%1 等)并将它们传递给真正的命令。这有可能以许多光荣的方式崩溃,但它可能会在您的情况下提供有用的解决方法。

于 2012-11-27T23:54:15.293 回答
0

根据 Keith Hills 的回答,这是我为此创建的批处理文件:

@ECHO OFF 
:: to install, place this dos_profile.bat script in the location you want 
:: it to reside and then run this batch script with the argument "register"
ECHO Commands defined by dos_profile.bat : F7, h, ls, cp, mv
IF "%1"=="register" (
  REG.exe ADD "HKCU\Software\Microsoft\Command Processor\Autorun" /ve /t REG_SZ /d "%CD%\dos_profile.bat" /f
  ECHO The DOS profile is registered.  Load a new command prompt and test a command.
)
@DOSKEY LS=DIR $* 
@DOSKEY CP=COPY $* 
@DOSKEY MV=MOVE $* 
@DOSKEY H=DOSKEY /HISTORY
于 2012-11-28T18:22:53.357 回答