Thanks to Will Sort for the guidance!
I have improved the code again:
I have improved the code again:
:: Eval.cmd - 2K/XP Expression Calculation Batch
:: Brglng - 2005.8.31
:: Thanks to: Will Sort modified on 2005.8.26
:: This batch file can only run in the Chinese version of NT-based Windows! It cannot run in DOS/Win9x/Me!
:: And do not use COMMAND.COM instead of CMD.EXE! Command.com cannot display Chinese, and its SET command is not as powerful as CMD.EXE
@echo off
setlocal
if /i "%1"=="/A" if "%2"=="" echo Must specify the file path! & goto end
if /i not "%1"=="/A" if /i not "%1"=="/N" if not "%1"=="/?" if not "%1"=="" goto EvalArgument
:EvalLogo
echo *****************************************************************
echo * Eval.cmd - 2K/XP Expression Calculation Batch *
echo * Brglng 2005.8.31 http://brglng.ys168.com *
echo * Thanks to: Will Sort modified on 2005.8.26 *
echo *****************************************************************
echo.
if not "%1"=="/?" echo Please enter the expression (enter "?" to view help, "Q" to exit) & goto inputExpr
:Help
echo Command line writing help:
echo.
echo %0
echo expression: Specify the expression to calculate
echo file path: If this parameter is specified, the expression and calculation result will be automatically saved to the specified file.
echo.
echo %0 : When running in normal mode, the calculation result is always automatically saved to the specified file.
echo %0 : When running in normal mode, only calculate and do not save to file.
echo %0 : View command line writing help
echo %0 : View command line writing help and expression writing help
echo.
echo If no parameters are used, it will enter the default calculation mode, and you need to enter the expression each time and
echo ask if you want to save to file.
if /i not "%2"=="Expr" goto end
echo.
pause
:ExprHelp
echo Expression writing help:
echo.
echo This expression calculation batch can handle simple calculations and does not support floating-point numbers and advanced mathematical functions.
echo It supports the following operations in descending priority order:
echo.
echo () - Grouping
echo ! ~ - - Unary operator
echo * / %% - Arithmetic operator
echo + - - Arithmetic operator
echo ^<^< ^>^> - Logical shift
echo - Bitwise "AND"
echo ^^ - Bitwise "XOR"
echo ^| - Bitwise "OR"
echo = *= /= %%= += -= - Assignment
echo ^&= ^^= ^|= ^<^<= ^>^>=
echo , - Expression separator
echo.
echo If calculating with parameters on the command line, any logical or remainder operator needs to enclose the expression string in quotes. Any non-numeric string key in the expression is used as an environment variable name. The value of these environment variable names should be defined before use. If not defined in the current environment, it defaults to zero. You can directly use the environment variable value for calculation without typing those %% symbols to get their values. Except that hexadecimal has a 0x prefix and octal has a 0 prefix, the numeric value is a decimal digit. Therefore, 0x12 is the same as 18 and 022. Please note that octal formulas may be easily confused: 08 and 09 are invalid numbers because 8 and 9 are not valid octal digits.
goto end
:EvalArgument
set /a EvalExpr="%1"
if "%EvalExpr%"=="" echo Expression input error! & goto end
echo %1=%EvalExpr%
if "%2"=="" goto end
echo %1=%EvalExpr% >>"%2"
echo The formula and calculation result have been saved to "%2"!
goto end
:inputExpr
set Expr=
set EvalExpr=
set /p Expr=>
if "%Expr%"=="" goto inputExpr
if "%Expr%"=="?" call:ExprHelp & goto inputExpr
if /i "%Expr%"=="Q" goto end
set /a EvalExpr="%Expr%"
if "%EvalExpr%"=="" echo Input error! & goto inputExpr
echo The calculation result is: %EvalExpr%
if /i "%1"=="/A" goto autosave
if /i "%1"=="/N" goto inputExpr
:if_save
set SaveEval=
set /p SaveEval=Do you want to save the expression and calculation result to a file ?
if /i "%SaveEval%"=="Y" goto save
if /i "%SaveEval%"=="N" goto inputExpr
goto if_save
:save
set /p SaveEvalPath=Please enter the file path and file name (such as C:\Windows\file.txt. If you only enter the file name, it will be automatically saved to the current folder, leave it blank for the last entered path):
echo "%Expr%"=%EvalExpr% >>"%SaveEvalPath%"
echo The expression and calculation result have been saved to "%SaveEvalPath%"!
goto inputExpr
:autosave
echo "%Expr%"=%EvalExpr% >>"%2"
goto inputExpr
:end
32位才是DOS未来的希望
个人网志:http://sololand.moe
个人网志:http://sololand.moe

DigestI