
【討論】批處理中的分隔符
echo命令中有6個(gè)分隔符,分別是:“./=;,”C:UsershelloworldDesktop>echo.C:UsershelloworldDesktop>echoC:UsershelloworldDesktop>echo/C:UsershelloworldDesktop>echo=C:UsershelloworldDesktop>echo;C:UsershelloworldDesktop>echo,
md命令中有4個(gè)分隔符,分別是:“,;=空格”C:UsershelloworldDesktop>md 1,2C:UsershelloworldDesktop>md 3=4C:UsershelloworldDesktop>md 5;6C:UsershelloworldDesktop>md 7 8
rd命令跟md命令相同。C:UsershelloworldDesktop>rd 1,2C:UsershelloworldDesktop>rd 3=4C:UsershelloworldDesktop>rd 5;6C:UsershelloworldDesktop>rd 7 8再檢測(cè)del命令的分隔符:1.創(chuàng)建文本,供del刪除;C:UsershelloworldDesktop>for /l %i in (12;1;21) do @echo >%i.txt2.檢測(cè)del的分隔符;C:UsershelloworldDesktop>del 12.txt=13.txtC:UsershelloworldDesktop>del 14.txt;15.txtC:UsershelloworldDesktop>del 16.txt,17.txtC:UsershelloworldDesktop>del 18.txt/19.txt無(wú)效開(kāi)關(guān) - 19.txt。C:UsershelloworldDesktop>del 18.txt19.txt目錄名稱(chēng)無(wú)效。C:UsershelloworldDesktop>del 18.txt.19.txt找不到 C:UsershelloworldDesktop18.txt.19.txtC:UsershelloworldDesktop>del 18.txt 19.txt3.檢測(cè)結(jié)果不難看出,del的分割符也是4個(gè),分別是:“,;=空格”
這里大膽的提出一個(gè)假設(shè),“,;=空格”4個(gè)分隔符是系統(tǒng)級(jí)的,在與命令語(yǔ)法不沖突的前提下(例:echo與空格),可以在任意命令中作為分隔符使用。用for反證一下:1.txt
code1nclick="copycode($('code0'));">復(fù)制代碼
- 小明
- 小紅
- 小強(qiáng)
code2nclick="copycode($('code1'));">復(fù)制代碼
- @echo off
- For /f tokens=1-2 delims=: %%i in ('Findstr /n .* 1.txt') do echo %%i=%%j
- pause
code2,提示出錯(cuò)“此時(shí)不應(yīng)有 ;delims=:”換成=號(hào),“此時(shí)不應(yīng)有 =delims=:”換成,號(hào),“此時(shí)不應(yīng)有 delims=:”nclick="copycode($('code2'));">復(fù)制代碼
- @echo off
- For /f tokens=1-2;delims=: %%i in ('Findstr /n .* 1.txt') do echo %%i=%%j
- pause
假設(shè)不成立。

