- ©«¤l
- 83
- ¥DÃD
- 73
- ºëµØ
- 0
- ¿n¤À
- 164
- ÂI¦W
- 0
- §@·~¨t²Î
- xp
- ³nÅ骩¥»
- Office 2003
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2013-8-12
- ³Ì«áµn¿ý
- 2015-12-13
|
BAT§å¦¸«ü¥O¡G SET ªº¥\¯à½d¨Ò¸Ô¸Ñ- ¤@
¥»©«³Ì«á¥Ñ a448488 ©ó 2013-8-15 23:00 ½s¿è
BAT§å¦¸«ü¥O¡G SET ªº¥\¯à½d¨Ò¸Ô¸Ñ- ¤@
-----------------------------------------------------------------------------------------------
¡E«ü¥O¡GSet
¡E»¡©ú¡G«Å§iÅܼơF³]©wÅܼơC
¡E³Æµù¡G¦bDOSÀô¹Ò¤U¿é¤JSet¡A¥i¦C¥XwindowsÀô¹ÒÅܼơC
¡E¥Îªk¡GSET gbs=%OS% §ä¨ú±o§@·~¨t²Î
SET xdate=%date% §ä¨ú±o¥Ø«e¤é´Á20130808
SET xmonth=%date:~5,2% §ä¨ú±o¥Ø«e¤ë¥÷08
SET select=
SET /P select=½Ð¿ï¾Ü¡G µ¥«Ý§ä¨ú±o¨Ï¥ÎªÌ©Ò¿é¤J¦r¤¸
¡E°Ñ¼Æ¡G[variable=[string]]
/P variable=[promptString]
/A expression
Àô¹ÒÅܼƨú¥N¤w¤U¦C¼W±j:
%PATH:str1=str2%
%PATH:~10,5%
%PATH:~-10%
%PATH:~0,-2%
-----------------------------------------------------------------------------------------------
SET [variable=[string]]
½d¨Ò:
--------------------------
@echo off
set var=§Ú¬OÈ
echo %var%
pause
--------------------------
½Ð¬Ý set var=§Ú¬OÈ ,³o´N¬OBATª½±µ¦b§å¦¸³B²z§@·~¤¤³]©wÅܼƪº¤èªk!
set ¬O«ü¥O var ¬OÅܼƦW = ¸¹¥kÃ䪺"§Ú¬OÈ"¬OÅܼƪºÈ
¦b§å¦¸³B²z§@·~¤¤n°Ñ¦Ò³oÓÅÜ´N§â var ÅܼƦW¥Î¨âÓ%(¦Ê¤À¸¹)¬A°_¨Ó,¦p%var%
³oºØSET»yªk¥u¯àª½±µ¦bBATì©l½X«e½á¤©ÅܼƪºÈ,¦³®ÉÔ»Ýn´£¨Ñ¤@ӥ椬¤¶±,
Åý¨Ï¥ÎªÌ¦Û¤v¿é¤JÅܼƪºÈ,µM«á§Ú̦b¨Ó®Ú¾Ú³oÓȨӰµ¬Û¹ï¾Þ§@,
--------------------------
SET /P variable=[promptString]
³oºØSETªº»yªk,¥u»Ýn¥[¤@Ó"/P"°Ñ¼Æ´N¥i¥H¤F!
½d¨Ò:
--------------------------
@echo off
set /p var=½Ð¿é¤JÅܼƪºÈ:
if %var% == 1 echo ±z¿é¤J¤F 1 ~_~
pause
--------------------------
set /p ¬O«ü¥O»yªk var ¬OÅܼƦW = ¸¹¥kÃ䪺"½Ð¿é¤JÅܼƪºÈ: ",³oÓ¬O´£¥Ü»y,¤£¬OÅܶqªºÈ!
°õ¦æ«á,¦b´£¥Ü»y«á±ª½±µ¿é¤J1,´N·|Åã¥Ü¤@¦C¿é¤Jªº 1 ~_~ ,¿é¤J§Oªº´N¨S¦³¥ô¦ó¤Ï¬M!
--------------------------
SET /A expression
/A «ü¥O¦C¶}Ãö«ü©wµ¥¸¹¥kÃ䪺¤å¦r¦ê¬°³Qµû¦ôªº¼Æ¦ì¹Bºâ¦¡¡C
¸Ó¹Bºâ¦¡µû¦ô¾¹«Ü²³æ¨Ã¥H»¼´îªºÀu¥ý¡]¶¶§Ç¡^¤ä´©¤U¦C¾Þ§@:
() - À£ÁY§Î¦¡
! ~ - - ³æ¤¸¹Bºâ¤l
* / % - ºâ¼Æ¹Bºâ¤l
+ - - ºâ¼Æ¹Bºâ¤l
<< >> - ÅÞ¿è¦ì²¾
& - «ö¦ì¡u»P¡v
^ - «ö¦ì¡u¤¬¥¸©Î¡v
| - «ö¦ì¡u©Î¡v
= *= /= %= += -= - ½áÈ
&= ^= |= <<= >>=
, - ¹Bºâ¦¡¤À¹j²Å¸¹
¤W±³o¨Ç¬O¨t²Î»¡©ú¸Ìªº¤º®e,²³æ½Ķ¤@¤U:
setªº/A°Ñ¼Æ´N¬OÅýSET¥i¥H¤ä´©¸s½×²Å¸¹¶i¦C¥[´îµ¥¤@¨Ç¸s½×¦ÛÅܼÆ!
²{¦bÁ|¨Ò¤l¤¶²Ð³o¨Ç¸s½×²Å¸¹ªº¥Îªk:
¬Ý½d¨Ò:
³o¸Ìªº¨Ò¤l½Ðª½±µ¦bCMD¤U½Æ»s«ü¥O°õ¦æ,¤£»ÝnÀx¦s¬°BAT!
set /a var=1 + 1
set /a ¤åªk, varÅܼƦW 1 + 1 ¸s½×¦¡¤l
½Æ»s°õ¦æ«á·|ª½±µÅã¥Ü¤@Ó2,©ÎªÌ°õ¦æ§¹«á§ÚÌ¿é¤Jecho %var%,¤]¬O¤G,
³o´N¬O¤@Ó²³æªº¥[ªk¦ÛÅܼÆ!
set /a var=2 - 1 µ²ªG¬O¦h¤Ö©O?¦pªG§A¬Ý¤£¦Üµ²ªG´Necho %var%.....
set /a var=2 * 2 ¼ªk¦ÛÅܼÆ
set /a var=2 / 2 °£ªk¦ÛÅܼÆ
set /a var=(1+1) + (1+1) µ²ªGµ¥©ó4 ¬Ý±oÀ´§a!
set /a a=1+1,b=2+1,c=3+1
°õ¦æ«á·|Åã¥Ü¤@Ó4,¦ý¥Îecho %a% %b% %c%«á¬Ýµ²ªG,·|µo²{¨ä¥L¸s½×¦ÛÅܼƤ]¦³®ÄªG!³o´N¬O"¤æ"¸¹ªº§@¥Î!
¦³®ÉÔ»Ýnª½±µ¦bìÅܼƶi¦C¥[´î¾Þ§@´N¥i¥H¥Î³oºØ»yªk
set /a var+=1 ³o¼Ëªº»yªk¹ïÀ³ì©l»yªk´N¬Oset /a var = %var% + 1
³£¬O¤@¼Ëªºµ²ªG,¦bìÅܼƪºÈ¤W¦b¶i¦C¸s½×¦ÛÅܼÆ,¤£¹L³o¼Ë¼g²³æ¤@ÂI
¦A¼g¤@Ó:
set /a var*=2
¨ä¥L³£³o»ò¥Î,¥un»¡©ú¦³³oÓ»yªk!
¥t¥~ÁÙ¦³¤@¨Ç¥ÎÅÞ¿è©Î§ä¨ú§E¹Bºâ¤l,³o¨Ç²Å¸¹,¨Ì·Ó¤W±ªº¨Ï¥Î¤èªk·|³ø¿ùªº.....
¤ñ¦p¦bCMD¸Ì¿é¤Jset /a var=1 & 1 "»P¦ÛÅܼÆ",¥¦¨Ã¤£·|Åã¥Ü¬°1,¦Ó¬O³ø¿ù,¬°¤°»ò?
¹ï©ó³o¼Ëªº"ÅÞ¿è©Î§ä¨ú§E¹Bºâ¤l",»Ýn§â¥¦Ì¥ÎÂù¤Þ¸¹¤Þ°_¨Ó,¬Ý¨Ò:
set /a var= 1 "&" 1 ³o¼Ëµ²ªG´NÅã¥Ü¥X¨Ó¤F,¨ä¥LÅÞ¿è©Î§ä¨ú§E¹Bºâ¤l¥Îªk
set /a var= 1 "+" 1 ¤¬¥¸©Î¦ÛÅܼÆ
set /a var= 1 "%" 1 §ä¨ú¼Ò¦ÛÅܼÆ
set /a var= 2 "<<" 2 ¦¸¤è¦ÛÅܼÆ
set /a var= 4 ">>" 2 ....
³o¨Ç²Å¸¹¤]¥i¥H¥Î&= ^= |= <<= >>= ³o¼ËªºÂ²³æ¥Îªk¦p
set /a var"&=" 1 µ¥©óset /a var = %var% "&" 1 ª`·N¤Þ¸¹
²{¦b»¡%PATH:str1=str2%
³oÓ¬O¨ú¥NÅܼÆȪº¤º®e
½d¨Ò:
--------------------------
@echo off
set a= bbs.verybat.cn
echo ¨ú¥N«eªºÈ: "%a%"
set var=%a: =%
echo ¨ú¥N«áªºÈ: "%var%"
pause
--------------------------
¹ï¤ñ¤@¤U,µo²{¥¦§âÅܼÆ%a%ªºªÅ¥Õ¦r¤¸µ¹¨ú¥N±¼¤F,±q³oÓ½d¨Ò,§ÚÌ´N¥i¥Hµo²{
%PATH:str1=str2%³oÓ¾Þ§@´N¬O§âÅܼÆ%PATH%ªº¸Ìªºstr1¥þ³¡¥Îstr2¨ú¥N
¤ñ¦p§â¤W±ªº¨Ò¤l§ï¦¨³o¼Ë
--------------------------
@echo off
set a=bbs.verybat.cn
echo ¨ú¥N«eªºÈ: "%a%"
set var=%a:.=¶Ë¸£µ¬%
echo ¨ú¥N«áªºÈ: "%var%"
pause
--------------------------
½Ķset var=%a:.=¶Ë¸£µ¬%
set«ü¥O varÅܼƦW ¦ra¬On¶i¦C¦r¤¸¨ú¥NªºÅܼƪºÈ,"."¬°n¨ú¥NªºÈ,"¶Ë¸£µ¬"¬°¨ú¥N«áªºÈ!
°õ¦C«á´N·|§âÅܼÆ%a%¸Ì±ªº"."¥þ³¡¨ú¥N¬°"¶Ë¸£µ¬"³o´N¬OsetªºÀH´«¦r¤¸ªº«Ü¦nªº¥\¯à!
%PATH:~10,5% ³o¬O¤°»ò·N«ä?
½d¨Ò:
--------------------------
@echo off
set a=bbs.verybat.cn
set var=%a:~1,2%
echo %var%
pause
--------------------------
°õ¦C«á,·|µo²{¥uÅã¥Ü¤F"bs"¨âÓ¦r¥À,ÅܼÆ%a%ªºÈ¤£¬O¬°bbs.verybat.cn¶Ü?
«ç»ò¥uÅã¥Ü¤F²Ä2Ó¦r¥À©M²Ä3Ó¦r¥À"bs",¤ÀªR¤@µ²ªG´N¥i¥H«Ü®e©ö¬Ý¥X
%PATH:~10,5%´N¬OÅã¥ÜÅܼÆPATH¸Ì«ü©w´X¦ìªºÈ!
¤ÀªRset var=%a:~1,2%
set«ü¥O varÅܼÆÈ a n¶i¦C¦r¤¸¾Þ§@ªºÅÜ¼Æ "1" ±qÅÜ¼Æ "a" ²Ä´X¦ì¶}©lÅã¥Ü "2" Åã¥Ü´X¦ì©M°_¨Ó´N¬O§âÅÜ¼Æ a ªºÈ,±q²Ä¤@¦ì¶}©l,§â«á¨â¦ì½á¤©µ¹ÅܼÆvar
´N¼Ë¦]¸Ó©ú¥Õ¤F§a~
--------------------------
¨ä¥L¨âºØ»yªk:
%PATH:~-10%
%PATH:~0,-2%
¤]¬OÅã¥Ü«ü©wÅܼƫü©w´X¦ìªºÈ±oªº·N«ä
%PATH:~-10%
½d¨Ò:
--------------------------
@echo off
set a=bbs.verybat.cn
set var=%a:~-3%
echo %var%
pause
--------------------------
³oÓ´N¬O§âÅܼÆa˼Æ3¦ìªºÈµ¹ÅܼÆVAR
·íµM§Ṳ́]¥i¥H§ï¦¨³o¼Ë
--------------------------
@echo off
set a=bbs.verybat.cn
set var=%a:~3%
echo %var%
pause
--------------------------
³oÓ´N¬O§âÅܼÆaªº±q²Ä3¦ì¶}©l«á±¥þ³¡ªºÈµ¹ÅܼÆVAR
%PATH:~0,-2%
½d¨Ò:
--------------------------
@echo off
set a=bbs.verybat.cn
set var=%a:~0,-3%
echo %var%
pause
--------------------------
°õ¦C«á,µo²{Åã¥Üªº¬O"bbs.verybat",¤Ö¤F".cn" ;±qµ²ªG¤ÀªR,«Ü®e©ö¤ÀªR¥X,³o¬O§âÅܼÆaªºÈ±q0¦ì¶}©l,¦Ü˼ƲĤT¦ì¤§¶¡ªºÈ¥þ³¡½á¤©µ¹var
¦pªG§ï¦¨³o¼Ë
--------------------------
@echo off
set a=bbs.verybat.cn
set var=%a:~2,-3%
echo %var%
pause
-------------------------- |
|