Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
可以自动将命令别名添加到DOS shell中吗?_Shell_Powershell_Dos - Fatal编程技术网

可以自动将命令别名添加到DOS shell中吗?

可以自动将命令别名添加到DOS shell中吗?,shell,powershell,dos,Shell,Powershell,Dos,有没有办法使我的Windows 7系统上的所有DOS外壳都具有此命令别名 doskey h=doskey /history 这是否可能,就像Bash shell可以加载.Bash_配置文件一样?我正在寻找一个不需要PowerShell的答案。简而言之:不需要。命令处理器cmd.exe和command.com不支持别名,正如您从bash和其他shell中了解到的那样 更详细的回答:您可以创建一个假别名,方法是制作巧妙的批处理文件,将参数%1等传递给真正的命令。这可能会以多种方式出现故障,但在您的

有没有办法使我的Windows 7系统上的所有DOS外壳都具有此命令别名

doskey h=doskey /history

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

简而言之:不需要。命令处理器cmd.exe和command.com不支持别名,正如您从bash和其他shell中了解到的那样


更详细的回答:您可以创建一个假别名,方法是制作巧妙的批处理文件,将参数%1等传递给真正的命令。这可能会以多种方式出现故障,但在您的情况下,它可能会提供一种可用的解决方法。

简而言之:不支持。命令处理器cmd.exe和command.com不支持别名,正如您从bash和其他shell中了解到的那样


更详细的回答:您可以创建一个假别名,方法是制作巧妙的批处理文件,将参数%1等传递给真正的命令。这有可能在许多方面崩溃,但它可能在您的情况下提供一个有用的解决方法。

在这里,Well 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来执行相同的操作。

在这里,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来执行相同的操作。

根据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

根据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

这似乎与问题相似:在该问题中投票表决的答案似乎比被接受的答案更详细。在研究这个问题时,我发现旧的autoexec.nt和config.nt在Windows 7中不再受支持,但如果您运行的是旧版本的Windows,则可能适用于您。这似乎与问题类似:在该问题中投票的答案似乎比接受的答案更详细。在研究这个问题时,我发现旧的autoexec.nt和config.nt在Windows 7中不再受支持,但如果您运行的是较旧版本的Windows,则可能适用于您。根据您的回答,我创建了一个批处理文件(见下文),该批处理文件将为您注册配置文件脚本。根据您的回答,我创建了一个批处理文件(见下文),该批处理文件将为您注册配置文件脚本。