- 將 list.txt 導向輸入給 sort 命令,sort命令排序處理之後,導向輸出到 alphlist.txt
- 若前一個指令的回傳值大於等於1,則用附加的方式導向輸出 ping taret fail 字串到 pinglog.txt 檔案
- quiz3.cmd
@echo off
rem 答案1
set today=%date:~5,2%/%date:~8,2%/%date:~0,4%
echo %today%
rem 答案2
for /F "tokens=1,2,3 delims=/ " %%a in ('date /t') do set today=%%b-%%c-%%a
echo %today%
- quiz4.cmd
@echo off
set /p myname=請輸入您的姓名:
set /p mybiryear=請輸入您的出生西元年:
set /a myage=2015 - mybiryear
echo.
echo %myname%您好,您的年齡為:%myage%歲
pause
- quiz5.cmd
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /L %%i in (2 1 9) do for /L %%j in (1 1 9) do (
set /a sum=%%i*%%j
echo %%ix%%j=!sum!
)
pause
- 因為沒有啟用延遲環境變數擴充功能,因此在括弧內的取用(echo %val%)會先作用,因此中間的echo 回應都是1,最後才執行變數的賦值(set val=3),所以最終echo的結果是3。
- showip.cmd
@echo off
rem route print | for /f "tokens=4" %i in ('find "0.0.0.0"') do @echo %i & exit /b
FOR /F "tokens=4 delims= " %%i in ('route print ^| find "0.0.0.0"') do echo %%i & goto NEXT
:NEXT
pause