ããããã¡ã¤ã«ã§æ°å¼ãæ±ã
Windowsã®cmd.exeã§ã¯ãsetã³ãã³ãã«ã/aããªãã·ã§ã³ãæå®ãããã¨ã§æ°å¼ãè©ä¾¡ã§ãã¾ãããã®æ©è½ãã©ã®ãããªãã®ãã確èªãã¦ã¿ã¾ããã*1
ã¯ããã«
æ¦è¦
cmd.exeã§ã¯ããset /a å¼ãã¨ãããã¨ã«ãããæ°å¼ãè©ä¾¡ã§ãã¾ãã*2 ã¾ããè©ä¾¡çµæãç°å¢å¤æ°ã«ã»ãããããã¨ãå¯è½ã§ãã詳細ã¯ããset /?ããåç §ãã¦ãã ããã
æ¼ç®åã«ã¤ãã¦
å¼ã®ä¸ã§ã¯ãCè¨èªã©ã¤ã¯ãªæ¼ç®åã使ã£ã¦ãååæ¼ç®ããããæ¼ç®ãè¡ããã¨ãã§ãã¾ããã¾ããè¤åä»£å ¥æ¼ç®åã使ãã¾ããæ¯è¼æ¼ç®å(==, !=, >, >=, <, <=)ãã¤ã³ã¯ãªã¡ã³ã(++)ããã¯ãªã¡ã³ã(--)ãè«çAND(&&)ãè«çOR(||)ã¯ä½¿ããªãããã§ãã
注æç¹
ããã¤ã注æç¹ãæ¸ãã¦ããã¾ãã
- ãset /aãã¯ãã³ãã³ãã©ã¤ã³ã¨ã³ãã³ãã¹ã¯ãªãã(ããããã¡ã¤ã«)ã§ä¸é¨ã®æåãç°ãªãã*3
- ã³ãã³ãã©ã¤ã³ã§ã¯ãè©ä¾¡ããå¼ã®å¤ããæ¨æºåºåã«åºåããã*4
- ã³ãã³ãã¹ã¯ãªããã§ã¯ãè©ä¾¡ããå¼ã®å¤ãèªåçã«åºåããããã¨ã¯ãªãã
- å¼ã®ä¸ã§ç°å¢å¤æ°ã使ãå ´åã¯ã%ã§å²ãå¿ è¦ã¯ãªãã(å²ãã§ãè¯ãã)
- æ±ãå¤ã¯ã符å·ä»ã32ãããæ´æ°ã®ã¿ã§ãããå°æ°ã¯æ±ããã¨ãã§ããªãã
- å¼ã¯äºéå¼ç¨ç¬¦ã§å²ãã§ããã®ããããããã§ãªãã¨ãã·ããæ¼ç®åãªã©ã®ä¸é¨ã®æ¼ç®åã§ã¨ã¹ã±ã¼ããå¿ è¦ã«ãªãã
- è©ä¾¡ããå¼ã®å¤ã¯ãç°å¢å¤æ°ã«ã»ãããã¦ä½¿ç¨ããã
- ifæã®æ¡ä»¶é¨ã®ä¸ã§ç´æ¥ä½¿ããããªãã¨ã¯ã§ããªãã
ãã¹ã
ããããã¡ã¤ã«ãä½æãããããããªå¼ããã¹ããã¦ã¿ã¾ããã(ããããã¡ã¤ã«ã®å é ã§ã@echo offãã¨ãã¦ãã¾ãããä¸è¨ã®ã³ã¼ãã§ã¯çç¥ãã¦ãã¾ãã)
ãã¹ã1 (ååæ¼ç®)
ååæ¼ç®ã®ãã¹ãã§ããè¨ç®çµæãç°å¢å¤æ°XãYãZã«ä»£å ¥ãããã®å¤ãechoã§è¡¨ç¤ºãã¾ããã¢ã¸ã¥ãæ¼ç®å(å°ä½æ¼ç®å)ã®ã%ãã¯ãããããã¡ã¤ã«ãªã®ã§ã%%ãã¨ãªãã¾ãã
set /a "X = (5 + 3) * (7 - 2), Y = X / 11, Z = X %% 11" echo X=%X%, Y=%Y%, Z=%Z%
X=40, Y=3, Z=7
ãã¹ã2 (æªå®ç¾©ã®ç°å¢å¤æ°)
æªå®ç¾©ã®ç°å¢å¤æ°ã使ã£ãå ´åã®ãã¹ãã§ããå¼ãè©ä¾¡ããåã«ãç°å¢å¤æ°Xãæ示çã«ã¯ãªã¢ãã¦ãã¾ããå¼ã®ä¸ã§æªå®ç¾©ã®ç°å¢å¤æ°ãç¾ããå ´åãå¤ã0ã§ãããã®ã¨ãã¦æ±ããã¾ãã
set X= set /a "X = X + 100" echo X=%X%
X=100
ãã¹ã3 (16é²è¡¨è¨ã¨8é²è¡¨è¨)
16é²è¡¨è¨ã¨8é²è¡¨è¨ã®ãã¹ãã§ãã0xã§å§ã¾ãæ°å¤ã¯16é²æ°ã0ã§å§ã¾ãæ°å¤ã¯8é²æ°ã¨ãã¦è©ä¾¡ããã¾ãã
set /a "X = 0x0034, Y = 012" echo X=%X%, Y=%Y%
X=52, Y=10
ãã¹ã4 (è¤åä»£å ¥æ¼ç®å)
è¤åä»£å ¥æ¼ç®åã®ãã¹ãã§ãã
set /a "X = 5, X += 1, X -= 2, X *= 3, X /= 4" echo X=%X%
X=3
ãã¹ã5 (è«çå¦å®)
è«çå¦å®ã®ãã¹ãã§ãã0ã®å ´åã¯1ãé0ã®å ´åã¯0ã«ãªãã¾ãã
set /a "X = !0, Y = !1, Z = !2" echo X=%X%, Y=%Y%, Z=%Z%
X=1, Y=0, Z=0
ãã¹ã6 (1ã®è£æ°ãããããã¨ã®AND)
1ã®è£æ°æ¼ç®(ãããå転)ã®ãã¹ãã§ããã¤ãã§ã«ãããããã¨ã®ANDããã¹ããã¦ãã¾ãã
rem ~0x35 = ~0b00110101 = 0b11001010 = 202 (8ãããè¨ç®) set /a "X = ~0x35 & 0xFF" echo X=%X%
X=202
ãã¹ã7 (å·¦ã·ãããããããã¨ã®OR)
å·¦ã·ããã®ãã¹ãã§ããã¤ãã§ã«ãããããã¨ã®ORããã¹ããã¦ãã¾ãã
rem 0b00101010 = 42 set /a "X = 1 << 1 | 1 << 3 | 1 << 5" echo X=%X%
X=42
ãã¹ã8 (å³ã·ãã)
å³ã·ããã®ãã¹ãã§ãããã«ããè¦ãã¨è«çã·ããã¨æ¸ãã¦ããã¾ãããå®éã¯ç®è¡ã·ããã®ããã§ãã
set /a "X = 0x000000FF >> 4, Y = 0xFFFFFF00 >> 1" echo X=%X%, Y=%Y%
X=15, Y=-128
ãã¹ã9 (ããããã¨ã®æä»çè«çå)
ããããã¨ã®æä»çè«çå(XOR)ã®ãã¹ãã§ãã
rem 0xAB = 0b10101011 rem 0xCD = 0b11001101 rem 0xAB ^ 0xCD = 0b01100110 = 102 set /a "X = 0xAB ^ 0xCD" echo X=%X%
X=102
ãã®ä»
- å¼ã®è¡¨è¨ã¯ãCè¨èªã®å¼ã®ãµãã»ããã¨èãã¦ããããã
- ããããã¡ã¤ã«ã§ã®æå¹ãªä½¿ãéããã¾ãæãã¤ããªãã
*1:Windows XP SP3ã§ç¢ºèªãã¾ããã
*2:aã¯arithmeticã®ç¥ã ã¨æãã¾ãã
*3:ããããã®ã¯ãããã¦ã»ããâ¦ã
*4:ã³ã³ãåºåãã§è¤æ°ã®å¼ãæå®ããå ´åã¯ãæå¾ã®å¼ã®å¤ã®ã¿ãåºåããã¾ãã