Linuxã«ãããã³ãã³ãã®çµäºã¹ãã¼ã¿ã¹ç¯å²
ã¨ã£ã¦ããã¾ããã ãã8ããããè¶ ããç¯å²ã®çµäºã¹ãã¼ã¿ã¹ã¯ä½¿ããªãã
- 符å·ãªãã®8ãããç¯å² (0-255) ã«éãããã
- 8ããããè¶ ããç¯å²ãè¿ãã¦ã9ãããç®ä»¥éã¯ç¡è¦ãããã
- 符å·ãªã表ç¾ãªã®ã§ -1 = 255 ã«ãªãã
æ¤è¨¼
æºå /tmp/return.sh
#!/bin/bash exit $1
å®è¡çµæ
# /tmp/return.sh 0; echo $? 0 # /tmp/return.sh 1; echo $? 1 # /tmp/return.sh 254; echo $? 254 # /tmp/return.sh 255; echo $? 255 # /tmp/return.sh 256; echo $? 0 # /tmp/return.sh 257; echo $? 1 # /tmp/return.sh 1000; echo $? 232 # /tmp/return.sh 1024; echo $? 0 # /tmp/return.sh -1; echo $? 255 # /tmp/return.sh -2; echo $? 254
åè
ã³ã³ãã¥ã¼ã¿ããã°ã©ãã³ã°ã«ãããããã»ã¹ã®çµäºã¹ãã¼ã¿ã¹ï¼è±: exit statusï¼ã¾ãã¯ãªã¿ã¼ã³ã³ã¼ãï¼è±: return codeï¼ã¨ã¯ãåããã»ã¹ï¼ã¾ãã¯å¼ã³åºãããå´ï¼ãå ·ä½çãªæç¶ããå§ä»»ãããã¿ã¹ã¯ãå®è¡å®äºããéã親ããã»ã¹ï¼ã¾ãã¯å¼ã³åºããå´ï¼ã«æ¸¡ãå°ããªæ°ã§ãããDOSã§ã¯ãããã¨ã©ã¼ã¬ãã« (errorlevel) ã¨å¼ã¶ãã¨ãããã
Unixç³»
Unixç³»ã§ã¯ãwaitã·ã¹ãã ã³ã¼ã«ãã»ããããã¹ãã¼ã¿ã¹ã¯åããã»ã¹ã®çµäºæã®å種æ å ±ãã¾ã¨ããããããã£ã¼ã«ãã§æ§æããã¦ãããåããã»ã¹ãæ£å¸¸çµäºããå ´åï¼WIFEXITEDãã¯ãã§å¤å®ãããä»ã«ã¯ã·ã°ãã«åä¿¡ã§çµäºãããããå ´åãããï¼ãSUSã§ã¯ã¹ãã¼ã¿ã¹ã®ä¸ä½8ããããåããã»ã¹ãè¨å®ããçµäºã¹ãã¼ã¿ã¹ã示ããã¨ã«ãªã£ã¦ãã[4]ããã®å¤ã¯ wait.h ã«å®ç¾©ããããã¯ã WEXITSTATUS ã§åå¾ãããã¨ãã§ããããã®ãããUnixç³»ã®çµäºã¹ãã¼ã¿ã¹ã®å¤ã¯0ãã255ã¾ã§ï¼8ããã符å·ãªãæ´æ°ï¼ã«éããã¦ããï¼ãã以ä¸ã®å¤ãæå®ãã¦ã親ããã»ã¹å´ãä¸ä½8ãããããåãåããªãï¼ã