如何使用批处理制作自定义命令?

How to make custom commands with batch?

我正在努力制作自己的自定义命令提示符,以便更轻松地完成工作。我已经成功创建了界面和 type 命令,但是当我尝试添加 help 命令时,它会回显菜单,但是我输入的 pause >nul 不起作用, window 刚刚关闭。你能帮我看看吗? 提前致谢!

@echo off
:HELLO
echo Hello!
pause >nul
cls
echo What can I do for you? Type in your commmand! (Type "help" to display a list of every command available.)
set /p command=
if %command%==type (
goto :TYPEFILENAME
)
if %command%==help (
goto :HELPLIST
)
:MAIN
cls
echo What can I do for you? Type in your commmand! (Type "help" to display a list of every command available.)
set /p command=
if %command%==type (
goto :TYPEFILENAME
)
if %command%==help (
goto :HELPLIST
)
pause >nul
:HELPLIST
echo ----------------------------------
echo Help: Page 1/1
echo Command | What it does
echo help    | displays this page
echo type    | types a file
echo ----------------------------------
pause >nul
goto :MAIN

如果您需要其余代码,请告诉我!这是我认为最重要的,所以我没有补充。

帮助部分崩溃的原因是横线 (|) 字符。 当你想像这样回显特殊时,你必须在它们前面添加一个转义字符(^)。 你的那部分代码应该是这样的:

echo ----------------------------------
echo Help: Page 1/1
echo Command ^| What it does
echo help    ^| displays this page
echo type    ^| types a file
echo ----------------------------------