当前也只能使用下面这种walk-around方案了。
如果大家还有更好的方法,请不吝赐教,谢谢。
func_lib.bat:
@echo off
:: main entry
set "func=%~1"
shift
goto %func%
goto:EOF
:: functions definitions show below
:bannerPingPong varref -- moves text in varref one step left or right and updates title
:: -- varref - variable name with banner text, format: "Banner Text------"
SETLOCAL ENABLEDELAYEDEXPANSION
set s=!%~1: =-!
if "!s:~-1!" NEQ "-" if "!s:~-1!" NEQ "+" set s=!s!--------
set d=!s:~-1!
if "!s:~0,1!" NEQ "-" set d=+
if "!s:~-2,1!" NEQ "-" set d=-
if "!d!"=="+" (set s=-!s:~0,-2!+) ELSE (set s=!s:~1,-1!--)
TITLE !s!
(ENDLOCAL & REM RETURN VALUES
IF "%~1" NEQ "" SET %~1=%s%
)
goto:EOF
app.bat:
@echo off
set "text=hi -"
for /l %%C in (1,1,15) do (
call func_lib.bat :bannerPingPong text
call echo.'%%text%%'
)
app.bat执行结果:
D:\root\rove\batch>.\app.bat
'-hi---+'
'--hi--+'
'---hi-+'
'----hi+'
'---hi--'
'--hi---'
'-hi----'
'hi-----'
'-hi---+'
'--hi--+'
'---hi-+'
'----hi+'
'---hi--'
'--hi---'
'-hi----'