ã¯ããã«
èªç§°æ¥æ¬äžã®ãPOSIX ããããïŒã·ã§ã«ã¹ã¯ãªããéå®ïŒããææ°ã® POSIX æºæ ã·ã§ã«ã¹ã¯ãªããã®äžçããæ¡å ããããŸããPOSIX ã®å€§å¹ ãªæ¹å®ã§ãã POSIX.1-2024 (IEEE 1003.1-2024, Issue 8) ã¯ã2024幎3æ21æ¥ã« The Open Group ã«ãã£ãŠæ¿èªããã5æ21æ¥ã« IEEE ã§æ¿èªããã6æ14æ¥ã«æ¹å®ãããŸãããããã§ããã€ãå çšäžæéã»ã©åã§ããæéã§ææ°æ å ±ããå±ãããããŠãããŸããååã®å€§å¹ ãªæ¹å®ã POSIX.1-2008 ãªã®ã§å®ã« 16 幎ã¶ãã®å€§å¹ æ¹å®ã§ãïŒPOSIX.1-2017ã¯å°èŠæš¡ãªä¿®æ£ïŒããªã ISO/IEC ã§ã®æ祚ã®ç· ãåãã¯6æ28æ¥ãªã®ã§ ISO/IEC ã®æ¿èªã¯ãŸã ã§ãããæ¿èªãããŠãªããšèšã£ãŠãæç¶ãäžã®éœåã«ãããã®ã§ãPOSIX ãšåŒã°ããŠããæšæºèŠæ Œã¯ 3 ã€ã®æšæºåå£äœïŒThe Open GroupãIEEEãISO/IECïŒãåãæšæºèŠæ Œãæ¡çšããããšã«ãªã£ãŠãã®ã§å 容ã«é¢ããŠç°è°ãåºãããšã¯ãªãã¯ãã§ãã
- æ å ±ããŒãž: https://www.opengroup.org/austin/
- POSIX ããã¥ã¡ã³ããžã®ãªã³ã¯
- The Open Group ç ïŒç¡æ HTML çã»7æ19æ¥å ¬éïŒ
- IEEE 1003 ç ïŒææïŒ
- ISO/IEC DIS 9945 ç ïŒææã»æ祚äžïŒ
- åè: POSIX ã³ãã³ãäžèŠ§ + SUS ã³ãã³ãäžèŠ§ å®å šç
ä»åã®æ¹å®ã§ã¯æšæºèŠæ Œã®ééãææ§ãªç¹ã®ä¿®æ£ã®ã»ãããããŸã§ bashism ãšèšãããŠããã·ã§ã«ã®æ¡åŒµæ©èœããGNU ã³ãã³ãã BSD ç³» Unix ã®ç¬èªã³ãã³ããæ¡åŒµããããªãã·ã§ã³ãªã©ãè¿œå ã»æšæºåãããããããªããå€æŽã«ãªã£ãæ©èœãå»æ¢ãããæ©èœããããŸããã¡ãŸãã«ãã POSIX æºæ ã·ã§ã«ã¹ã¯ãªããã®æ å ±ã®ããã€ãã¯å€ããªã£ãŠããŸããŸããããã®èšäºã§ã¯ä»åã®æ¹å®ã§ã·ã§ã«ãã³ãã³ããã©ãå€ããã®ãã«ã€ããŠè§£èª¬ããŸããéèŠãªç¹ã¯ããããæžããŠãããšæããŸãããæŒãããã£ããåŸã§è¿œå ããŸãããŸããå°æ¥ã®æ¹åæ§ããšããŠä»åã®æ¹å®ã«ã¯å«ãŸããŠããªããå°æ¥å€æŽãããããããªãæ å ±ãšãæ°ããæšæºåãããæ©èœã«ãŸã 察å¿ããŠããªãå®è£ ã®ããã®ãåé¿çããããã€ã解説ããŠããŸãã
ãå°æ¥ã®æ¹åæ§ã(FUTURE DIRECTIONS) ã¯å°æ¥ã®POSIXã§æšæºåããããšæ±ºãŸã£ãããšã§ã¯ãããŸãããPOSIX ããã®ããã«ããããšèããŠããããšã§ãããå®çŸãããã©ãã㯠OS ã®å®è£ è ãåæããŠãã®å 容ã«å¯Ÿå¿ããããšãåæã§ãã
POSIX.1-2024 ã®æ¹å®ã§ã¯ POSIX ãåç §ãã C èšèªã C99 ãã C17 ã«å€æŽã«ãªããŸããããã ãæ¬èšäºã«ã¯ C èšèªã«ã€ããŠã®è©±ã¯ãããŸãããã ã£ãŠ C èšèªã«è©³ãã人ãªãäœäººãããã§ãããïŒ ç§ã倪åæã¡ã§ããäžçã§ã¯ãªãã®ã§ä»ã®äººã«ä»»ããŸãããšã¯èšããã®ã®ããã ãã§ã¯ã¡ãã£ãšå¯ããã®ã§ãæ°ããè¿œå ã»åé€ãããé¢æ°ãžã®ãªã³ã¯ã ã玹ä»ããäºå®ã§ãã
æ°ããè¿œå ã»åé€ããã POSIX ã€ã³ã¿ãŒãã§ãŒã¹
- C èšèªçš
- ã·ã§ã«&ã³ãã³ã
- ããŸã
- POSIX 2024 Changes: https://sortix.org/blog/posix-2024/
- POSIX.1-2024 ã§ã®å€æŽç¹ããŸãšãããµã€ãïŒC èšèªçšãšã·ã§ã«çšã®äž¡æ¹ïŒ
POSIX ããåé€ãããã€ã³ã¿ãŒãã§ãŒã¹ã¯ãPOSIXããå®è£ ããŠã¯ãããªãããå®è£ ããåé€ããããšåœä»€ããŠããããã§ã¯ãªããã移æ€æ§ããªããïŒãã䜿çšããå Žåã¯æ³šæãå¿ èŠïŒãšããæå³ã§ããçŸå®ã®å®è£ ã¯ãæ¡åŒµæ©èœããšããŠãããããå®è£ ããŠæ§ããŸãããã移æ€æ§ã«æ³šæããã®ã§ããã°äœ¿çšããŠãæ§ããŸãããããã¯ãæ¡åŒµæ©èœã䜿çšãã POSIX æºæ ã¢ããªã±ãŒã·ã§ã³ããšåŒã°ããŸãã
POSIX ãæ¹å®ããããšèšã£ãŠãåŸæ¹äºææ§ãç Žå£ãããããªå€æŽãèŠæ±ãããŠããããã§ã¯ãªãã®ã§å®å¿ããŠãã ããããã ãããã«ã¯é倧ãªäºå®ããããŸããããã¯ä»çŸåšãå OS éã§äºææ§ããªãåäœã POSIX ã®æ¹å®ã§åãåäœã«çµ±äžããããã®ããªããšããããšã§ãããªããªãã©ã® OS ã§ãåãåäœã«çµ±äžãããšããããšã¯ãã©ããã® OS ã§ã¯åäœãå€æŽããã°ãªãããåŸæ¹äºææ§ãç Žå£ãããŠããŸãããã§ããå®å¿ããŠãã ãããPOSIX ãã©ãã ãæ¹å®ããããããåŸæ¹äºææ§ãä¿ã€ããã«ç§»æ€æ§ïŒç°ãªã OS éã®äºææ§ïŒã¯ç ç²ã«ãªã£ãŠããã移æ€æ§ããªãéšåã¯ããããããã£ãšç§»æ€æ§ã¯ãªããŸãŸãªã®ã§ãå¥ã®ã·ã¹ãã ã«ä¹ãæãããšãã¯æ³šæãå¿ èŠã§ãããä»ãŸã§äœã£ãã·ã§ã«ã¹ã¯ãªãã㯠OS éçºè ãåŸæ¹äºææ§ãä¿ãšããšããéããåã OS ãšãã®åŸç¶ããŒãžã§ã³ã§ãªãåãããã«åäœããã¯ãã§ãã
ãã®èšäºã®ä¿®æ£å±¥æŽïŒå€§ããªãã®ã®ã¿ïŒ
- 2024-06-23: dash ã§
$'...'
ã«å¯Ÿå¿ããä¿®æ£ãè¡ãããŠããããšãè¿œèš - 2024-06-29:
compress
/uncompress
/zcat
ã³ãã³ãã«ã€ããŠå ç - 2024-06-30: bash ã§
cd
ã³ãã³ãã«ç©ºæåãæå®ãããšãã®æåã«ã€ããŠè¿œèš - 2024-06-30: ãçºæãããªããã®æå³ã«ã€ããŠè£è¶³
ããªãã¯èª°ïŒ
ããŸã«ã¯èªå·±çŽ¹ä»ãšèšãããç§ããã©ã€ããŒãã§ãã£ãŠããããšã®çŽ¹ä»ãããããšæããŸãã宣äŒãªã®ã§èå³ããªãæ¹ã¯ãå ãžã©ããã
ç§ã¯ã·ã§ã«ã¹ã¯ãªããã®äœæã楜ã«ããããã®ã©ã€ãã©ãªãããŒã«ãéçºããŠããŸãããã£ãšãæåãªä»£è¡šäœã¯ ShellSpec ã§ããæè¿ GitHub ã®ã¹ã¿ãŒã 1K ãè¶
ããChatGPT ããã 100 åã« 1 åãããã®ç¢ºçã§ç§ã®ããšãèªç¥ããŠãããããã«ãªããŸãããã©ããã® Unix/Linux ã®ïŒæºïŒå
¬åŒããã±ãŒãžã«ãå«ãŸããŠãããšãããªããšãïŒèª°ããåæã«ãã£ãŠãã®ã§ãªã¢ã«ã«ææ¡ããŠãªãïŒãShellSpec ã¯ã·ã§ã«ã¹ã¯ãªããçšã®é«æ©èœãªãã¹ããã¬ãŒã ã¯ãŒã¯ã§ãbash ã ãã§ã¯ãªããã¹ãŠã® POSIX ã·ã§ã«ãšãããåãç°å¢ã«å¯Ÿå¿ããŠããã®ãç¹åŸŽã§ããã©ã®ç°å¢ã§ãåãããã«ããããã«ãããã㪠POSIX ã³ãã³ãã ãã«äŸåããã»ãŒãã¹ãŠãã·ã§ã«ã¹ã¯ãªããã®èšèªïŒã·ã§ã«èšèªïŒã§å®è£
ããç°å¢äŸåããªããããã®é«åºŠãªã·ã§ã«ããã°ã©ãã³ã°æè¡ã䜿ãããŠããŸãããã°ããéçºãåæ¢ããŠããã®ã§ããïŒãŸã æ¬èª¿åã§ã¯ãããŸãããïŒåå§åããŸãããæè¿ã®ä¿®æ£ã§ã¯ AIX 7.2 / 7.3 äžã® bash ãš ksh93 ãžã®å¯Ÿå¿ãè¡ãããŠããŸãïŒ/bin/sh
= ksh88f ãžã®å¯Ÿå¿ã¯ ksh88f ã®ãã°ã®åœ±é¿ç¯å²ã倧ããä¿çäžãSolaris 10 ã® ksh88i ã§ã¯åäœããã ksh88 ã¯åºæ¬çã« POSIX æºæ ã§ã¯ãªããPOSIX ã«å®å
šã«æºæ ããŠãªãå€ããã ksh88f ãæªãïŒãåœç¶ãªãã ShellSpec ã¯ïŒäžéšã®ç°å¢ãé€ããŠïŒCI ã«ããç¶ç¶çãªãã¹ããè¡ãããŠããŸãã
ã·ã§ã«ã¹ã¯ãªããã®å€§ããªåé¡ç¹ã®äžã€ã¯ç§»æ€æ§ã®äœãã§ããããã¯äžè¬çãªã·ã§ã«ã¹ã¯ãªãããç°å¢äŸåã®ã³ãã³ããããªãã¡ Unix/Linux ã«æšæºã§å«ãŸããŠãã OS æšæºã³ãã³ãïŒPOSIX ã³ãã³ããå«ãïŒã«å€§ããäŸåããŠããã®ãåå ã§ããäžè¬çã«å®è£ ã®æ°ãå€ããã°å€ãã»ã©å®è£ éã®äºææ§ã¯äœããªããŸããOSæšæºã³ãã³ãã¯è€æ°ã® Unix ãã³ããŒãå£äœãããããåããããªã³ãã³ããç¬ç«ããŠäœã£ãŠããã®ã ããäºææ§ãäœããªãã®ã¯åœããåãšèšããŸããPOSIX ã¯äºææ§åé¡ã解決ããããšããå£äœã§ã¯ãªãããŠã§ãã®æšæºèŠæ Œãäœã£ãŠãã WHATWG ãšã¯å šãæ¹éãéãæšæºåå£äœã§ãããã®ãããªçŸç¶ã§ãã©ã®ç°å¢ã§ãåãã·ã§ã«ã¹ã¯ãªããããéçºããã®ã¯è³é£ã®æ¥ã§èª°ã§ãç°¡åã«ã§ãããããªããšã§ã¯ãããŸãããã©ã®ç°å¢ã§ãåãã·ã§ã«ã¹ã¯ãªããçšã®ãã¹ããã¬ãŒã ã¯ãŒã¯ãïŒShellSpec èªç以åã¯ïŒãªãã£ãããšãã移æ€æ§ãé«ãã·ã§ã«ã¹ã¯ãªãããéçºããã®ãé£ããã£ãçç±ã®äžã€ã§ããããShellSpec ã§ã¯ãã¹ãã«ç¬èªã® DSL ïŒã·ã§ã«ã¹ã¯ãªããäºæïŒã䜿çšããŸãããDSL ã䜿çšããŠããéãã¯ãã¹ãã³ãŒãã«ç§»æ€æ§ãããåäžã®ãã¹ãã³ãŒãã§å šãŠã®ã·ã§ã«ã®ãã¹ããè¡ãããšãå¯èœã§ãã
ShellSpec 㯠LinuxãmacOSãBSD ç³» UnixãSystem V ç³» UnixïŒSolaris ãš AIXïŒãWindows (WSL äžã® Linux ã ãã§ã¯ãªãCygwin ã BusyBox ãªã©ãå«ãïŒ ãªã©ãã©ã®ç°å¢ã§ãåããŸããã©ã®ç°å¢ã§ãåããšããã®ã¯ãã©ã® OS ã§ãåããšããæå³ã ãã§ã¯ãªããäžçäžã©ã®å Žæã§ãåããšããããšã§ããæè¿è¡ã£ã AIX 察å¿ã®å
容ã®äžã€ã¯ AIX ç°å¢ã® time
ã³ãã³ããåå ã§çºçããŠãããã±ãŒã«äŸåããªããããã®ä¿®æ£ã§ãïŒC ãã±ãŒã«ã«å€æŽããã®ã§ã¯ãªãïŒçŸåšã®ãã±ãŒã«ãå°éããŠã©ã®ãã±ãŒã«ç°å¢ã§ãåãããã«ä¿®æ£ããŠããŸãããã®ä¿®æ£ã§ ShellSpec ã察å¿ããç°å¢ã¯æŽã«å¢ããŸãããããã®äŸããããããããã«ç°å¢ããšã«ã³ãã³ãã®åäœãéãããã©ã®ç°å¢ã§ãåãã·ã§ã«ã¹ã¯ãªãããæžãã®ã¯é£ããã®ã§ãããã¹ãŠã®ç°å¢ã®åäœãææ¡ããŠããã«ããããã察å¿ããŠæžãã人ã¯ãŸãããŸãããåé¡ã¯åŸããèŠã€ãããŸããåŸããä¿®æ£ãããå¿
èŠããããŸããããããå
šãŠã®åãã¹ããå¿
èŠã§ãã
人ã¯ã ãã§ããã¹ãããŸããæåããå®ç§ã«æ£ããåãã³ãŒããæžããããšã¯ãããŸãããã·ã§ã«ã¹ã¯ãªãããç°å¢ã«äŸåããååšã§ãã以äžãç°å¢äŸåã®åé¡ãå®ç§ã«ææ¡ããŠãã人以å€ã¯å¿ ããã°ãå«ããŠããŸããŸããããã«å¯ŸåŠããã«ã¯å€æ°ã®ç°å¢ããšã«ãã¹ããè¡ããããããŸãããããªãã¯æåããå®ç§ãªã³ãŒããæžããïŒ ããšãããã ãšããŠãæ®éã¯äžäººã§éçºããããã§ã¯ãªãã®ã§ãããªãã ããã§ããŠãæå³ã¯ãããŸãããçµéšã®æµ ã人ãå®ç§ãªã³ãŒããæžãããšãããé©ãã¹ãããšã§ããããã§ãããã¹ãã¯å¿ ãå¿ èŠãªã®ã§ãããããŠãã®ãã¹ãã¯èªååããå¿ èŠããããŸãããããã¹ãèªååã®ä»çµã¿ããªããã°æäœæ¥ã§ãã¹ããè¡ãç®èŠã§çµæã確èªãããããªããªã£ãŠããŸããŸããããã®äœãæªãã®ãã¯èšããŸã§ããããŸããããïŒ ç°å¢æ¯ã«è¡ãæäœæ¥ã§ç®èŠã«ãããã¹ãã¯æéãããããã¹ãçºçããŸããã©ã®ãããªãã¹ããããã®ãšããèšé²ããªãããã¹ãäœæ¥ãåé¡ãªãè¡ã£ãã®ããããããä¿®æ£ãããšãã«å šäœãåãã¹ãããã®ãäžå¯èœã ããã§ãããã®ãããªãã¹ãã®ããæ¹ãèš±ãããã®ã¯ 20ïœ30 幎åãŸã§ã§ããã·ã§ã«ã¹ã¯ãªããã¯äœæ¥ãèªååããããã«äœããã®ã ãšèšãã®ã«ããã®ã·ã§ã«ã¹ã¯ãªããã®ãã¹ããæäœæ¥ã«é Œãããã§ã¯ç®è以å€ã®äœç©ã§ããããŸããã
念ã®çºã§ããã©ã®ãããªã·ã§ã«ã¹ã¯ãªããã§ããã¹ãããããšãã話ã§ã¯ãããŸããã䜿ãæšãŠã§ééãããšããªããããªæ°è¡çšåºŠã®å°ããªã·ã§ã«ã¹ã¯ãªããã§ããã°ãã¹ãã¯äžèŠã§ãããã¹ããå¿ èŠãªã®ã¯å€æ°ã®ã·ã§ã«ã¹ã¯ãªããã®çµã¿åããã§åã倧ãããŠè€éãªã·ã¹ãã ãé«ãä¿¡é Œæ§ã移æ€æ§ãå¿ èŠãªãã®ã ãã§ããã ãã倧æµã®äººã«ã¯å¿ èŠãããŸããããããããã§ãå¿ èŠãªå ŽåããããŸãããã¹ãããªããã°ä»ã®ç°å¢ã§åãã調ã¹ãããšãã§ããŸããããå®å¿ã㊠OS ã®ããŒãžã§ã³ãã¢ããããŒãããããšãã§ããªããªã£ãŠããŸããŸããPOSIX ã«æºæ ããŠæžããŠããã°ããã£ãšåããããããŸãããã§ã¯ãªããåããšããä¿èšŒãå¿ èŠãªã®ã§ããç°å¢ãå€ãããã³ãŒããä¿®æ£ãããšãã«åé¡ãªãåããšããä¿èšŒãã§ããªããã°ãé·ã䜿ããã·ã§ã«ã¹ã¯ãªããã«ã¯ãªããŸããã
é£ãããšã¯ãã ShellSpec ã®å®çŸã«ããã©ã®ç°å¢ã§ãåãã·ã§ã«ã¹ã¯ãªãããäœãããšãå¯èœã§ããããšã¯èšŒæãããŸãããç§ããã£ãŠãã掻åã¯ã·ã§ã«ã¹ã¯ãªããã®ç°å¢äŸåã®åé¡ããªãããŠãæ®éã«ã·ã§ã«ã¹ã¯ãªãããæžãã ãã§ãã©ã®ç°å¢ã§ãåãã·ã§ã«ã¹ã¯ãªãããç°¡åã«äœãããããªåºç€ãäœãããšã§ããPOSIX ã«æºæ ããŠã·ã§ã«ã¹ã¯ãªãããæžããšããã®ã¯ãšãŠãéå¹çãªäœæ¥ã§ããPOSIX ã«æºæ ããäœæ¥ã¯ã·ã§ã«ã¹ã¯ãªãããæžãäžã§ã®æ¬åœã®ç®çã§ã¯ãããŸãããã移æ€æ§ãé«ãããšããŠãä»ã®ç°å¢ã«ç§»æ€ããããšèªäœãã»ãšãã©ãªããªã£ãŠããŸã£ãçŸä»£ã§ã¯ç§»æ€æ§ã«åããããã§ããã®åªåã¯å ±ãããŸãããããããªããç§ã¯ OS ã«ã¯å€æ§æ§ãããã¹ãã ãšèããŠããã®ã§ Linux 以å€ã® BSD ç³» Unix ã System V ç³» Unix ãç¡èŠãããã¯ãããŸãããPOSIX æºæ ã移æ€æ§ã®å®çŸãšããåªåããããšããåæã« POSIX ã«æºæ ããŠé«ã移æ€æ§ãå®çŸãããŠãããããã«ããã®ãæçµç®æšã§ããä»ã®èšèªã§ã¯äœå¹Žãåããå®çŸã§ããŠããããšãªã®ã§ããã®ç¹ã§ã·ã§ã«ã¹ã¯ãªããã¯å€§ããé ããŠããŸãããã¡ããç®æšã¯ç§»æ€æ§ã®å®çŸã ãã§ã¯ãªãããã°ã®ãªãã·ã§ã«ã¹ã¯ãªããã誰ã§ãç°¡åã«æžããããã«ããããšãç®æšã®äžã€ã§ããããã®æžãæ¹ã«ã¯åé¡ããããã ãããšããç¡é§ç¥èïŒãããããŠããŠïŒãã²ããããããããããããã®ã§ã¯ãªãããªãããŠããŸãã®ãç®æšã§ãããšã¯èšããã®ãããªäžçãããã«äœãããšã¯ã§ããªãã®ã§ãã®ãããªèšäºãæžããŠææ°æ å ±ãåºããŠããŸãã
ãã®ä»ã®ã·ã§ã«ã¹ã¯ãªããã«é¢ããç§ã®ç 究ã®ææã¯ãã¡ãã§å ¬éããŠããŸãããã¹ãŠïŒæ¹å®åã®ïŒPOSIX ã§æšæºåãããŠããã·ã§ã«ãšã³ãã³ãã®æ©èœã®ã¿ã䜿ã£ãŠå®è£ ããŠããŸãããããã䜿ãã°ã·ã§ã«ã¹ã¯ãªãããæžãã®ã¯å¹Ÿå楜ã«ãªãã§ãããã
-
https://github.com/ko1nksm-shlab
- sh-string - æååæäœã©ã€ãã©ãªïŒçœ®æã trim åŠçãªã©ïŒ
- sh-path - ãã¹åæäœã©ã€ãã©ãªïŒæ¡åŒµåã®é€å»ããã¹ã®æ£èŠåãªã©ïŒ
- sh-datetime - æ¥ä»ã©ã€ãã©ãªïŒUNIXæéãšã®å€æãææ¥ã®ååŸïŒ
-
seq.awk - awk ã«ãã
seq
ã³ãã³ãçžåœæ©èœã®å®è£ - sh-maketemp - äžæãã¡ã€ã«ããã£ã¬ã¯ããªäœæã©ã€ãã©ãª
-
sh-pipestatus - pipefail ãš PIPESTATUS æ©èœã®å®è£
- ããŸã: SIGPIPE ã«ãããšã©ãŒãç¡èŠããããã®é¢æ°
-
sh-findcmd -
which
ã³ãã³ãã®çžåœæ©èœã®å®è£ - sh-xorshift - Xorshift ã«ããç䌌乱æ°çæã©ã€ãã©ãª
- sh-fnv1 - FNV1ããã·ã¥å€èšç®ã©ã€ãã©ãª
- sh-base64 - Base64 ãšã³ã³ãŒããŒã»ãã³ãŒããŒ
- sh-hmac-sha1 - HMAC-SHA1 ã®å®è£
äžéšã®ããŒã«ã¯å人ã®ã¡ã€ã³ãããžã§ã¯ãã«ãããŠããŸãã
- getoptions - ã·ã§ã«ã¹ã¯ãªããçšã®ãªãã·ã§ã³ããŒãµãŒ
- shdotenv - ã·ã§ã«çšã®dotenvïŒç°å¢å€æ°ã®èšå®ïŒããŒã«
-
readlinkf - POSIX ã³ãã³ãã®ã¿ã䜿ã£ã
readlink -f
ã®äºæå®è£ - url - URL ãšã³ã³ãŒãã»ãã³ãŒããç°¡åã«è¡ãããŒã«
- sh-i18n - åœéåïŒç¿»èš³ïŒã©ã€ãã©ãª
åæç¥è
POSIX ãªã©ã«é¢ããåæç¥èã®è©±ã§ããèå³ããªã人ã¯é£ã°ããŠãã ããã
POSIX.1-2024ã®æ°æ©èœã¯ãã§ã«äœ¿ããŸãïŒ
èšäºã®ã¿ã€ãã«ã§ã·ã§ã«ã¹ã¯ãªããã¯ã©ãå€ããã®ãïŒãšæžããŸãããïŒç°å¢ã«ãã£ãŠã¯ïŒäœå¹Žãåããæ°ããæ©èœã䜿ããŠããŸãããªãæšæºèŠæ Œãã§ããåããæ°ããæ©èœã䜿ããŠããã®ããšèšããšãPOSIX ãè¡ã£ãŠããæšæºåäœæ¥ãšã¯ãæ°ããæ©èœãäœãããšã§ã¯ãªãæ¢åã®å®è£ ã®åäœãææåããããšã ããã§ãããã¡ãã§ãinventionããšããããŒã¯ãŒãã§æ€çŽ¢ããŠã¿ããšããããŸãããPOSIX ã§ã¯ãçºæãè¡ããªããããšã¯å ±éèªèã§ããã€ãŸãæ°ããæ©èœããçºæããããã®ã§ã¯ãªããå é²ç㪠POSIX ã·ã§ã«ã§ãã bash ã ksh ããGNU ã³ãã³ãã BSD ã³ãã³ããªã©ã«å®è£ ãããŠãããããããæ¡åŒµæ©èœããã移æ€æ§ãé«ãéèŠã ãšæãããæ©èœãæšæºèŠæ Œã«çµã¿èŸŒãŸããŸãããæ¡åŒµæ©èœãšããèšèã¯å°ã 誀解ãæããããèšèã§ããPOSIX ã«ãšã£ãŠã¯æšæºåãããŠããªãæ©èœã¯ãã¹ãŠæ¡åŒµæ©èœã«ããããŸãããäžéšã®æ©èœã¯ POSIX ãèªçãããããåããã·ã§ã«ãã³ãã³ããæã£ãŠããæ©èœã§ããïŒPOSIX ã¹ã¬ãããªã©ã®äŸå€ã¯ãããŸããïŒåºæ¬çã« POSIX ã¯åŸãããã£ãŠããŠç§»æ€æ§ã®èŠ³ç¹ããæšæºåãã¹ã OS ã®æ©èœãéžå¥ããŠããã ãã§ãããã·ã§ã«ãã³ãã³ããå«ã OS ã®æ©èœãäœãã®ã¯ãæããå Unix/Linux ã®éçºè ã®åœ¹ç®ã§ãã
POSIX ã¯çºæãè¡ããªããããæšæºåãããæ©èœãšããã®ã¯ãã§ã«äœå¹Žãåãã䜿ããæ©èœã§ãããããã£ãŠ POSIX ã«ãã ãã£ãŠããªã人ã«ãšã£ãŠã¯ãã§ã«äœ¿ã£ãŠãããã®æ©èœããæšæºåããããšããã ãã§ããããã§ã¯ POSIX.1-2024 ã®æ¹å®ã«ã¯ã©ãããæå³ãããã®ã§ããããïŒ ããã¯ãç§ã®ãã㪠ãPOSIX æºæ ïŒã·ã§ã«ã¹ã¯ãªããïŒã«ãããã人ããã¢ããããŒãããªããã°ãããªãç¥èããšããã ãã§ããä»ãŸã§ POSIX ã§èŠå®ãããŠãªããã䜿ããªãïŒäœ¿ããªãïŒãšèšã£ãŠããããã®æ©èœãã®äœ¿çšãæšæºèŠæ Œäžã¯è§£çŠãšãªããããããèšãå¿ èŠããªããªã£ããšããããšã§ããäžè¬çã«ä»äœ¿ã£ãŠããã·ã¹ãã ãå€ã OS ãäºææ§ã®ãªãã·ã¹ãã ã«ç§»è¡ããããšã¯ãªãã§ããããããPOSIX ã§æšæºåãããæ©èœã¯ãçŸåšäœ¿ããã®ã§ããã°ä»åŸãå®å¿ããŠäœ¿ããã¯ãã§ãã
2024-06-30 è£è¶³ ãçºæãè¡ããªãããšããã®ã¯ãæ°ããæ©èœããè¿œå ããªããšããæå³ã§ãããã§ã«å®è£ ãããŠããæ©èœãšã»ãŒåãæ©èœãæšæºåã®ããã«å°ã調æŽãããããŠã䌌ããããªæ°ããã€ã³ã¿ãŒãã§ãŒã¹ãè¿œå ããããšã¯ãããŸãããŸãäœäºã«ãäŸå€ã¯ããã®ã§æšæºåã®éçšã§ã©ãããŠãå¿ èŠãšå€æãããå Žåã«ã¯çºæãè¡ãããããšãããã§ãããã
åç°å¢ã®å¯Ÿå¿ç¶æ³ã¯èªåã§èª¿ã¹ããããããŸãã
POSIX ãæ¹å®ããæ°ããæ©èœãäžéšã®ç°å¢ã䜿ãããšèšã£ãŠããç°å¢ã«ãã£ãŠã¯ãã®ãŸãŸã§ã¯äœ¿ããªããããããªããã§ããïŒ ãšèšãããããã®ãšããã§ãããããªãåç°å¢ã POSIX.1-2024 ã«æºæ ãããšçºè¡šãããŸã§äœ¿ããªãããããšãªããŸãããã¡ãã£ãšåŸ ã£ãŠãã ããããã€ãŸã§å€ã POSIX æšæºèŠæ Œãåç §ããŠã·ã§ã«ã¹ã¯ãªãããæžãæ°ã§ããïŒ å€ãã®ç°å¢ã¯ POSIX ã«æºæ ããŠãããšæèšããŠããŸããããPOSIX ã®å€ãããŒãžã§ã³ã«ããæºæ ããŠããªãå ŽåããããŸãããããåŸ ã£ãŠãåç°å¢ãã©ã® POSIX ã®ããŒãžã§ã³ã«å¯Ÿå¿ããŠããããªããŠãïŒäžéšãé€ããŠïŒå ¬è¡šãããããšã¯ãããŸãããPOSIX æšæºèŠæ Œã¯ POSIX ãæšæºèŠæ ŒãšããŠãŸãšãããã ã®ææžã§ãããªããçŸå®ã® Unix/Linux ã®åäœã¯æžããŠãããŸãããPOSIX ã¯ïŒç¹å®ã®ããŒãžã§ã³ã®ïŒPOSIX ã«æºæ ããŠããç°å¢ãšïŒåãããŒãžã§ã³ã®ïŒPOSIX ã«æºæ ããŠããã¢ããªã±ãŒã·ã§ã³ã®çµã¿åããã§ããã°ãå¥ã®ç°å¢ãšã®éã«ç§»æ€æ§ãå®çŸã§ããã¯ãã ãšäž»åŒµããŠããã ãã§ãå Unix/Linux éã«äºææ§ãããããšãä¿èšŒããŠããŸããããããäžäœã©ã®ç°å¢ãã©ã® POSIX ã®ããŒãžã§ã³ã«æºæ ããŠãããã ïŒãšãã話ã«ãªããŸãããæ£åŒã«å ¬è¡šãããŠããã®ã¯æ¬¡ã®ç°å¢ã ãã§ãã
OS | æºæ ããŒãžã§ã³ | è£è¶³ |
---|---|---|
macOS version 14.0 | POSIX.1-2001 (SUSv3) | |
IBM AIX 5, 6, 7.1 | POSIX.1-2001 (SUSv3) | ãµããŒãçµäºOS |
Solaris 10, 11 | POSIX.1-2001 (SUSv3) | UNIXèªèšŒã®æå¹æéåã |
HP-UX 11i V3 B.11.31 | POSIX.1-2001 (SUSv3) | |
INTEGRITY | POSIX.1-2003 | POSIX.1-2001ã®ä¿®æ£ç |
IBM AIX 7.2 ä»¥äž | POSIX.1-2008 (SUSv4) | |
Solaris 11.4 | POSIX.1-2008 (SUSv4) | UNIXèªèšŒã®æå¹æéåã |
ãŸã ãªã | POSIX.1-2024 (SUSv5) | |
å Linux | æèšãªã | |
å BSDç³»Unix | æèšãªã |
- POSIXæºæ ãšèªãããã OS äžèŠ§
- UNIXïŒPOSIXæºæ ãèŠä»¶ã®äžã€ïŒãšèªãããã OS äžèŠ§
POSIX.1-2024 ã¯åºãã°ããã ããããã°ããã¯äžã€åã® POSIX.1-2008 ãåç §ããããšèãããããããŸãããããã macOS ãªã©ã¯ããã«åã® POSIX.1-2001 ãŸã§ã®å¯Ÿå¿ããå ¬è¡šããŠããŸãããSolaris ã¯ä»¥å㯠UNIX ã®èªèšŒãåããŠããã®ã§äžå¿ POSIX ã«æºæ ããŠãããšåé¡ããŠããŸãããå®éã«ã¯ UNIX èªèšŒã®æŽæ°ãè¡ã£ãŠãããæå¹æéåããšãªã£ãŠããŸããã€ãŸããããŸã§ã®ææ°ã§ãã POSIX.1-2008 ã«æºæ ããŠãããšèªããããŠããã®ã¯äºå®äž IBM AIX 7.2 以éãããªããšããããšã§ããçµæ¯éè¿ã® HP-UX ãæŽæ°ãããšã¯èãã«ããã§ãããmacOS ã UNIX ã®èªèšŒãåããçµç·¯ãèªãéã蚎èšå¯Ÿçã§ãããªããããmacOS 㯠20 幎以äžåã®å€ã POSIX æºæ ã®ãŸãŸã§ãå ¬åŒã«ã¯ææ°ã® POSIX ã®ããŒãžã§ã³ã«ã¯è¿œåŸããªãã®ã§ã¯ãªãããšç§ã¯èããŠããŸãã
macOS ã POSIX.1-2001 ãŸã§ãã察å¿ããŠããªããšããã®ã¯ããããŸã§ Open Group ãè¡ã£ãŠãã UNIX ã®èªèšŒã§ã®è©±ã§ããå®éã«ã¯ POSIX.1-2008 ã«ïŒã»ãŒïŒæºæ ããŠãããšããŠãäžå®å šã§ãããšããéããããèªèšŒãã¹ããè¡ã£ãŠããªãã ããšããå ŽåããããŸããPOSIX.1-2024 ã«æºæ ããŠããªããšããã®ã¯ãPOSIX.1-2024 ã§æšæºåãããæ©èœããã£ãã䜿ããªããšããæå³ã§ã¯ãããŸãããã»ãšãã©ã®æ©èœã䜿ãããšããŠãèªèšŒãã¹ãã«åæ Œããªããã°æºæ ããŠããªããšããŠæ±ãããŸããmacOS ã®å€ãã®ã³ãã³ã㯠FreeBSD çãå°å ¥ããŠãããFreeBSD ã¯æ°ããæšæºèŠæ Œãžã®å¯Ÿå¿ãç¶ç¶ããŠè¡ã£ãŠããŸãããããã£ãŠ macOS ãããŒãžã§ã³ã¢ãããããã³ã«æ°ããæ©èœã¯å¢ããŠããŸãããã ã macOS ã® sh 㯠FreeBSD sh ã§ã¯ãªãå€ã bash ãªã®ã§ POSIX.1-2024 ã«æºæ ããã®ã§ããã°äœãããã®å¯Ÿå¿ãå¿ èŠã§ããå€ããšã¯ããé«æ©èœãª bash ããäœæ©èœãª FreeBSD sh ã«å€æŽãããšäºææ§ãä¿ãããªãããåçŽã«å€æŽããããšã¯ãŸãèããããŸãããå€ãã®ã³ãã³ãã¯ãã§ã« POSIX.1-2024 ã«å¯Ÿå¿ããŠããŠã sh ãé察å¿ãªã POSIX.1-2024 ã«æºæ ãšå ¬è¡šãããããšã¯ãããŸãããmacOS ã® sh ãä»åŸã©ããªãã®ãã¯çŸæç¹ã§ã¯èª°ã«ãããããŸããããå Linux ãã£ã¹ããªãã¥ãŒã·ã§ã³ããã®ä»ã® BSD ç³» Unix ã POSIX ã«ã»ãŒæºæ ããŠãããšèšãããŠããŸããããããã©ããŸã§æºæ ããŠãããã¯äžæã§ãã
å®ã¯ getconf
ã³ãã³ãã䜿çšããŠå Unix/Linux ã察å¿ããŠãã POSIX ã®ããŒãžã§ã³ã調ã¹ãããšãã§ããŸãã
OS | _POSIX_VERSION |
---|---|
macOS 13.4 | 200112 |
FreeBSD 14.0 | 200112 |
NetBSD 10.0 | 200112 |
OpenBSD 7.5 | 200809 |
Ubuntu 22.04 | 200809 |
FreeBSD ã§ã¯ 2024-05-31 ã« 200112 ãã 200809 ãžã®å€æŽãããããè¡ãããŸããïŒäžåºŠééã㊠200808 ãšæžããŠããŸã£ãŠããŸããïŒã
- https://cgit.freebsd.org/src/commit/?id=2e30926a68
- https://cgit.freebsd.org/src/commit/?id=6e0278408e
macOS 㯠FreeBSD ã®ãŠãŒã¶ãŒã©ã³ãã®ã³ãã³ãã䜿çšããŠããããããã®ãã㧠200112 ã®ãŸãŸã ã£ãå¯èœæ§ãèããããŸãããã·ã§ã«ãã«ãŒãã«ã¯ FreeBSD ã®ãã®ã§ã¯ãªããããFreeBSD ãå€æŽã«ãªã£ããããšèšã£ãŠ macOS ãæŽæ°ããããšã¯éããªãã§ããããSolaris 10 ãš 11 ã§ã¯ãã£ã¬ã¯ããªããšã«æºæ ããŒãžã§ã³ãç°ãªããã€ããªãé
眮ãããŠãã以äžã®ããã«ãªããŸããSolaris ã§ã¯é©å㪠POSIX ã®ããŒãžã§ã³ã«æºæ ããç°å¢ããç°å¢å€æ° PATH
ãèšå®ããŠäœãå¿
èŠããããŸããããã©ã«ãã® /usr/bin/getconf PATH
ã§ã¯äžã€åã®ããŒãžã§ã³ãåç
§ããŠããããšã«æ³šæããŠãã ããã
- Solaris 10
-
/usr/bin/getconf
- _POSIX_VERSION: 199506
- PATH: /usr/xpg4/bin:/usr/ccs/bin:/usr/bin:âŠ
-
/usr/xpg4/bin/getconf
- _POSIX_VERSION: 199506
- PATH: /usr/xpg4/bin:/usr/ccs/bin:/usr/bin:âŠ
-
/usr/xpg6/bin/getconf
- _POSIX_VERSION: 200112
- PATH: /usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:âŠ
-
- Solaris 11
-
/usr/bin/getconf
- _POSIX_VERSION: 200809
- PATH: /usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:âŠ
-
/usr/xpg4/bin/getconf
- _POSIX_VERSION: 198808
- PATH: /usr/xpg4/bin:/usr/bin:âŠ
-
/usr/xpg6/bin/getconf
- _POSIX_VERSION: 200112
- PATH: /usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:âŠ
-
/usr/xpg7/bin/getconf
- _POSIX_VERSION: 200809
- PATH: /usr/xpg7/bin:/usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:âŠ
-
ãã®ããã«å¯Ÿå¿ããŠãã POSIX ã®ããŒãžã§ã³ã¯èª¿ã¹ãããšãã§ããŸããããããŸã§ã·ã¹ãã å šäœã®è©±ã§ãããåã ã®ã³ãã³ãã®å¯Ÿå¿ç¶æ³ã¯ããããŸããããå Unix/Linux 㧠ç¹å®ã® POSIX ã®ããŒãžã§ã³ã«æºæ ããç°å¢ãäœãæ¹æ³ã¯ããŸããŸã§ããããããã®çµè«ã¯ãããããã®ç°å¢ã§ã©ã®æ©èœã䜿ããããªããŠãæããèªåã§èª¿ã¹ãªããšããããªãããšã ãšããããšã§ããPOSIX ãšããæšæºèŠæ Œããã£ããšããŠããçŸå®ã®å®è£ ã¯ææ°ã® POSIX ã«æºæ ããŠããªãå Žåããã°ã§æ£ããåããªãå ŽåããããŸãããããã POSIX ã«æºæ ããŠããå®è£ ã®éã§ãåäœãç°ãªãããïŒPOSIX ã¯äžéšã®ä»æ§ã§åäœã®éãã蚱容ããŠããïŒãPOSIX ãšããæšæºèŠæ Œããã£ããããšèšã£ãŠãçŸå®ã®å®è£ 㧠100% ã®äºææ§ãä¿èšŒãããŠããããã§ã¯ãããŸããã100% ã®äºææ§ãä¿èšŒããã®ã§ããã°ãããã¯ã¢ããªã±ãŒã·ã§ã³ïŒã·ã§ã«ã¹ã¯ãªããïŒãéçºããããã°ã©ãã®åœ¹ç®ã§ãã
ãïŒ POSIX ã«æºæ ããŠã©ã®ç°å¢ã§ãåãã·ã§ã«ã¹ã¯ãªãããéçºããã®ã¯å€§å€ã§ããïŒ
å®æã« POSIX ã«æºæ ããŠã·ã§ã«ã¹ã¯ãªãããæžããšãããã®ã³ãã³ãããªãã·ã§ã³ã¯ POSIX ã§èŠå®ãããŠãªãããããã¬ãããã¬ããšãã人ãããŸãããPOISX ãåç §ããŠæ¬åœã«ç§»æ€æ§ãããã·ã§ã«ã¹ã¯ãªãããæžãã人ãªããŠã»ãšãã©ããªããŠã倧æµã®å Žåã¯åé¡ã«ãªãæžãæ¹ãããŸããŸå«ãŸããŠããªããŠãããŸããŸåããŠããïŒããã«èŠããïŒã ãã§ããæ¬æ°ã§ã©ã®ç°å¢ã§ãåãã·ã§ã«ã¹ã¯ãªãããéçºããã®ã¯ãä»ã®èšèªã«æ¯ã¹ããšãšãŠã倧å€ãªãã§ãããã¹ããèªååãããã¹ããã¬ãŒã ã¯ãŒã¯ãªãã«ããããããªãã®ã§ã¯ãããŸãããïŒã ããç§ã¯ ShellSpec ãäœããŸããããæ®éã®äººã¯ãããªããšãããªããŠããã§ããïŒ
POSIXã®ç®ç
POSIX ãšã¯ Portable Operating System Interface ã®ç¥ã§ã¢ããªã±ãŒã·ã§ã³ãããŸããŸãª OS ã«ç§»æ€ããããããããã« OS ã®ã€ã³ã¿ãŒãã§ãŒã¹ãæšæºåãããã®ã§ãããã°ãã° POSIX 㯠Unix ãäœãããã®ä»æ§ã ãšãåéããããŠããŸãããPOSIX ã®ç®ç㯠Unix 以å€ãå«ãããŸããŸãª OS ãžã®ã¢ããªã±ãŒã·ã§ã³ã移æ€ã§ããããã«ããããšã§ããPOSIX ã®ç®çã¯ä»¥äžã«èšãããŠããŸãã
- ã¢ããªã±ãŒã·ã§ã³æå
- å®è£ ã§ã¯ãªãã€ã³ã¿ãŒãã§ãŒã¹ïŒã©ã€ãã©ãªé¢æ°ãšã·ã¹ãã ã³ãŒã«ã¯åºå¥ãªãïŒ
- CèšèªïŒä»æ§ã¯ ISO C æšæºã§æå®ãããŠããæšæº C èšèªã®ãçšèªãã§èšè¿°ãããïŒ
- ã¹ãŒããŒãŠãŒã¶ãŒãªããã·ã¹ãã 管çãªã
- æå°éã®ã€ã³ã¿ãŒãã§ãŒã¹ãæå°éã®å®çŸ©
- å¹ åºãå®è£ å¯èœ
- éå»ã®å®è£ ã«å¯Ÿããæå°éã®å€æŽ
- æ¢åã®ã¢ããªã±ãŒã·ã§ã³ã³ãŒãã«å¯Ÿããæå°éã®å€æŽ
ãã®æšæºã®éçºè ã¯ã以äžãå«ãæ¢åã®ã·ã¹ãã ãæœåšçãªã·ã¹ãã ãå«ãå¹ åºãç¯å²ã§ãæå®ããããã¹ãŠã®æ©èœãå®è£ ã§ããããã«åªããïŒ
- ãªãªãžãã«ã® UNIX ã·ã¹ãã ã³ãŒããã掟çããçŸåšã®äž»èŠã·ã¹ãã ãã¹ãŠ
- ãªãªãžãã«ã® UNIX ã·ã¹ãã ã³ãŒãã«ç±æ¥ããªãäºæã·ã¹ãã
- ãŸã£ããç°ãªããªãã¬ãŒãã£ã³ã°ã·ã¹ãã äžã§ãã¹ãããããšãã¥ã¬ãŒã·ã§ã³
- ãããã¯ãŒã¯åãããã·ã¹ãã
- åæ£ã·ã¹ãã
- å¹ åºãããŒããŠã§ã¢äžã§åäœããã·ã¹ãã
POSIX ã¯ããŸã£ããç°ãªããªãã¬ãŒãã£ã³ã°ã·ã¹ãã äžã§ãã¹ãããããšãã¥ã¬ãŒã·ã§ã³ãã§å®è£
ã§ããããæšæºèŠæ ŒãäœãããŠããŸããã€ãŸããã㯠Windows äžã® Cygwin ã WSL ãšããŠå®è£
ããŠãæ§ããªããšããããšã§ããPOSIX ãæ±ããŠããã®ã¯ Unix ãæã£ãŠãã OS ã®ã€ã³ã¿ãŒãã§ãŒã¹ãå®è£
ããŠãUnix çšã®ã¢ããªã±ãŒã·ã§ã³ã移æ€ããããããããšãã§ãããUnix ãšããŠã®æ§èœãä¿¡é Œæ§ãå®çŸãã OS ã®éçºãæ±ããŠããããã§ã¯ãããŸãããããä»®ã«äžãã OS ãäœããšã㊠POSIX ã«å®å
šã«æºæ ãããŠéçºãããšããŠããçãæ³åãããã㪠Unix ã®ãã㪠OS ãäœãããšã¯ã§ããŸããããªããªã Unix ã«åãã£ãŠããã¯ãã®ã·ã¹ãã 管çïŒããŒããŠã§ã¢ç®¡çããŠãŒã¶ãŒç®¡çãªã©ïŒãç°¡åã«èšãã° root æš©éãå¿
èŠãªãã®ã¯ POSIX ã§æšæºåã®å¯Ÿè±¡ç¯å²ã§ã¯ãªãããã§ããWindows 㧠sudo
ã³ãã³ããããããå©çšã§ããããã«ãªã£ããšè©±é¡ã«ãªããŸããããsudo
ã³ãã³ããªã©ã¯æããã« POSIX ã§æšæºåãããããããªãã³ãã³ãã§ãã
ãŠã€ã³ããŠã·ã¹ãã ã POSIX ã«å«ãŸããŠããªãã®ã§ãç¥ã£ãŠã®éã Unix ã§ããã¯ãã® macOS ã® GUI ã¯ä»ã® Unix ãšã¯å šãç°ãªãç¬èªä»æ§ã§ããGUI 㯠Unix çã§ã¯ãªããšããã®ã macOS ãåªããŠããçç±ã®äžã€ã§ãããã OS ãäœãããã«å¿ èŠãªãã®ãã¹ãŠã POSIX ã®å¯Ÿè±¡ç¯å²ã«å«ãŸããŠãããšãããããã㯠Unix ãäœãããã®æšæºèŠæ Œã«ãªã£ãŠããŸã Unix 以å€ã® OSïŒäŸãã° WindowsïŒã¯ OS ã Unix ã«äœãå€ããªãéã POSIX ã«æºæ ãããããªããªã£ãŠããŸããŸããOS ã«ãå€æ§æ§ããã£ãã»ããè¯ãã§ãããïŒ Unix ç³» OS ã®éã§ãã移æ€æ§ããªãã®ã§ããã°ãããã¯ç§»æ€æ§ããã OS ã®ã€ã³ã¿ãŒãã§ãŒã¹ã§ã¯ãªããåãªã Unix ã®ã€ã³ã¿ãŒãã§ãŒã¹ã§ããPOSIX 㯠Unix ã®å®è£ ãåèã«äœãããŸããããäœããã OS ã®ã€ã³ã¿ãŒãã§ãŒã¹ã¯ Unix ã«éå®ãããã®ã§ã¯ãªãã®ã§ãããã ã POSIX ã®æ¡åŒµèŠæ Œã§ãã SUS (Single Unix Specification) ã¯ãèªå®ãã¹ãã«åæ ŒãããšãUnix ãåä¹ããæš©å©ãäžãããããšããæšæºèŠæ Œã§ããããæå³ Unix ãäœãããã®æšæºèŠæ ŒãšèšããŸããããã®å éšå®è£ 㯠Unix ã®ãã㪠OS ã§ãªããŠãæ§ããŸãããçå±ã®äžã§ã¯èªå®ãã¹ãã«åæ Œããããã°ãçŸåšã® Windows ã®å§¿ã®ãŸãŸ Unix ãåä¹ãããšã ã£ãŠã§ããŸããPOSIX ã«ã¯äœããã«ãŒãã«ã§å®è£ ããªããã°ãªããªããªã©ãšã¯å®çŸ©ãããŠããªãã®ã§ãUnix ãåä¹ãããã« Windows ã®ã«ãŒãã«ã Linux ã Unix ã«å€æŽããå¿ èŠã¯ãããŸããããããã POSIX ã¯ã«ãŒãã«ã®ã·ã¹ãã ã³ãŒã«ãšã©ã€ãã©ãªé¢æ°ã®åºå¥ãæå³çã«ããŠããŸããã
POSIX æšæºèŠæ Œã¯ãã§ã«ååšãã Unix/Linux ãå
ã«äœãããŠããŸããPOSIX æšæºèŠæ Œãå
ã« Unix/Linux ãäœãããŠããããã§ã¯ãããŸãããäŸãã°ä»åã®æšæºèŠæ Œã§è¿œå ããã timeout
ã³ãã³ãã®ä»æ§ã¯ OpenBSD (FreeBSD) ã®ããã¥ã¢ã« (man ããŒãž) ããåã£ãŠãããã®ã§ããããšãæèšãããŠããŸããïŒåèïŒ
Add the timeout utility.
Here is the current manual page as present on OpenBSD, taken from
FreeBSD, under 2-clause BSD license:
ãã®ããã« POSIX æšæºèŠæ Œã¯å®åšãã Unix/Linux ã® man ããŒãžãå®éã®åäœãå ã«äœãããŠããŸããPOSIX ãè¡ã£ãŠããæšæºåãšããã®ã¯ãä»æ§ãäœãããšã§ã¯ãªãå®åšãã Unix/Linux ã®ä»æ§ãã¢ããªã±ãŒã·ã§ã³ã®ç§»æ€æ§ã®èŠ³ç¹ãã圹ã«ç«ã€ããã«ãŸãšããããšã§ããPOSIX ã«æžãããŠããã®ã¯ãã©ã®ç°å¢ã§ãå šãåãåããããããšãä¿èšŒãããã³ãã³ããšãªãã·ã§ã³ã®äžèŠ§ã§ã¯ãããŸãããPOSIX ã«æžãããã³ãã³ããšãªãã·ã§ã³ã ãã䜿ãã°ããã ãã§ç§»æ€æ§ãå®çŸã§ãããšããåçŽãªè©±ã§ã¯ãªããããã°ã©ãã¯ç§»æ€äœæ¥ãè¡ãå¿ èŠããããŸããPOSIX ã«ã¯ã¢ããªã±ãŒã·ã§ã³ïŒã·ã§ã«ã¹ã¯ãªãããå«ãïŒãä»ã® OS ã«ç§»æ€ãããšãã«ãå OS ã®äºææ§ããªãéšåãªã©ã®äœã«æ°ãã€ããªããã°ãªããªãããæžãããŠãããPOSIX ãèªãã§å®éã®ç°å¢ã®åäœã調ã¹ãŠ ãã©ã®ç°å¢ã§ãåãããã«äœãäœæ¥ãè¡ããã®ã¯ããã°ã©ãã®ä»äºã§ããã©ã®ç°å¢ã§ãåã移æ€æ§ãé«ãã¢ããªã±ãŒã·ã§ã³ãäœããšãã«ãããã°ã©ããèªãã§åœ¹ã«ç«ã€ãã®ã POSIX ãšããæšæºèŠæ Œæžãªã®ã§ãã
POSIX æšæºèŠæ Œã§ç¹ã«åœ¹ç«ã€ã®ã¯ãæªæå®ãããå®è£
å®çŸ©ããšæžããŠããéšåã§ãããæªæå®ãããå®è£
å®çŸ©ããšæžããŠããéšåã¯ãå Unix/Linux ã§åäœãéããšãããå€æããŠãããšããæå³ãªã®ã§ãå®éã®ç°å¢ã§ã®åäœã調ã¹ãªããã°ãããªãéšåãšããŠåœ¹ã«ç«ã¡ãŸããäŸãã°ä»åã®æ¹å®ã§ã¯ãod
ã³ãã³ã㧠-A n
ãæå®ãããšãã«ããŒã¿ã®æçµè¡ã®æ¬¡ã«ã¢ãã¬ã¹ã ãã®è¡ãåºåãããããããªãããæ確ã«æžãããŠããªããšããææãããä¿®æ£ãããŸããïŒåèïŒãæ¹å®ã«ãã£ãŠããåºåãããããããªããã¯æªæå®ã§ããããšæ確ã«ãªã£ããã®ã§ãPOSIX æšæºèŠæ Œãèªãã ããã°ã©ãã¯ãã®äºã«æ°ã¥ããŠãåºåãããŠããããªããŠãåé¡ãªãããã«äž¡æ¹ã®åäœã«å¯Ÿå¿ããã·ã§ã«ã¹ã¯ãªãããæžãããã®ãã£ããã«ãªããŸããPOSIX æšæºèŠæ Œãã¢ããªã±ãŒã·ã§ã³ã移æ€ãããšãã«åœ¹ã«ç«ã€ãšããã®ã¯ããããã話ãªã®ã§ãã
å Unix/Linux ã®åäœã¯çŽ°ããåããéããŸãããPOSIX ãæªæå®ãå®è£ å®çŸ©ãšæ±ºããããå Unix/Linux ããã©ãã©ã®åäœã§å®è£ ããŠããŸã£ãã®ã§ã¯ãããŸãããå Unix/Linux ã§åäœããã©ãã©ã ã£ããããPOSIX ã¯äºææ§ãä¿ã€ããã«ä»æ§ãå€æŽãããæªæå®ãå®è£ å®çŸ©ãšããä»æ§ãã§æšæºåããŠããã°ã©ãã«å¯Ÿå¿ãä¿ããããªãã£ãã®ã§ããPOSIX ã¯å Unix/Linux é㧠100% ã®äºææ§ãä¿èšŒããæšæºèŠæ Œã§ã¯ãªãã100% ã®ç°å¢ã§åãã¢ããªã±ãŒã·ã§ã³ãäœãããã®ã§ããã°ããã°ã©ããé 匵ããããããŸããããã®ãããªé¢åãããªããããã«ãä»ã®èšèªã§ã¯ 100% ã®äºææ§ãå®çŸããŠããªã POSIX å±€ã®äžã«ãèšèªãã©ã€ãã©ãªã«ããç°å¢ã®éããåžåããå±€ãäœãããšã§ãã»ãŒ 100% ã®äºææ§ã20幎ãåããå®çŸããŠããŸãããã®ä»çµã¿ã«ãã£ãŠäžè¬ã®ããã°ã©ãã®éçºã®è² æ ãæžãããªãããPOSIX ç°å¢ä»¥å€ãå«ããã¹ãŠã®ç°å¢ã§ã¢ããªã±ãŒã·ã§ã³ãåããããšãå®çŸããŠããŸããã·ã§ã«ã¹ã¯ãªãããå«ãã¢ããªã±ãŒã·ã§ã³ã®ç§»æ€æ§ãé«ããããã«ã¯ç°å¢äŸåãé«ã Unix/Linux ã®åºæ¬æ©èœïŒPOSIX ã€ã³ã¿ãŒãã§ãŒã¹ã POSIX ã³ãã³ããªã©ãå«ãïŒããçŽæ¥ã䜿ããªãããšãéèŠãªèãæ¹ã§ããç§ãç®æããŠããã®ã¯ POSIX ãæèããããšãªããä»ã®èšèªäžŠã¿ã®ç§»æ€æ§ãã·ã§ã«ã¹ã¯ãªããã®äžçã«ããããããšã§ãã
POSIXã®æãç«ã¡
POSIX 㯠IEEE 1003 æšæºèŠæ Œã«å¯ŸããããããããåŒã³åã§ãGNU ãããžã§ã¯ãã§æå㪠Richard Stallman ãååãèæ¡ããŸããããããŸã§ïŒæšæºèŠæ Œã®çå®äžïŒã¯èª°ããåä»ãã IEEEIX ãšåŒã°ããŠãããPortable Operating System ãšãããµãã¿ã€ãã«ãä»ããŠããŸããããã®ãµãã¿ã€ãã«ã®ç¥ã§ãã POS ã« IEEEIX ãšåã IX ãçµã¿åãããŠäœãããçšèªã POSIX ã§ãããããã IX ã¯åœæã® UnixïŒMicrosoft ãéçºããäžçåã®åçš Unix ã§ãã Xenix ãªã©ïŒãæ«å°Ÿã« IX ãã€ããååããã䜿ã£ãŠããããšããæ¥ãŠãããšæãããŸããçŸåšã§ã¯ I 㯠Interface ã®ç¥ãšã㊠POSI ãšãªããæåŸã® X ã«ã¯ç¹ã«æå³ã¯ãªããšãããŠããŸãã
æšæºå㯠1970 幎代åŸåãã 1980 幎代ååã«ãããŠå€æ°ã®ã³ã³ãã¥ãŒã¿ã¡ãŒã«ãŒãç¬èªã«éçºããŠãã Unix éã§äºææ§ãäœããªããããããã® Unix çšã«ã¢ããªã±ãŒã·ã§ã³ãéçºããã®ã倧å€ã«ãªã£ãããã«å§ãŸããŸããããç¬èªã«éçºããŠãã Unixããšããã®ã¯ãAT&T ãã Unix ã®ã³ãŒããšã©ã€ã»ã³ã¹ãè³Œå ¥ããããäºå®äžã®ãªãŒãã³ãœãŒã¹ã§ãã BSD Unix ãå ã«ãèªåãã¡ã販売ããã³ã³ãã¥ãŒã¿çšã« Unix ã移æ€ãããšããæå³ã§ããå Unix éã®äºææ§ãäœããªã£ãçç±ã¯ Unix ãæèŒããã³ã³ãã¥ãŒã¿ã販売ããã³ã³ãã¥ãŒã¿ã¡ãŒã«ãŒã¯ Unix ã移æ€ããã ãã§ã¯ãªããä»ç€Ÿãããããåªãã Unix ãšããŠæ¹è¯ãå ãããšåæã« API ã顧客ãå²ã蟌ãããã®ãã³ããŒããã¯ã€ã³ãšããŠå©çšããããã§ããåœæã® Unix ã®å€ã㯠OS åäœã§é åžããããã®ã§ã¯ãªãã³ã³ãã¥ãŒã¿ã®ä»å±åã§ãããœãŒã¹ã³ãŒãã¯éå ¬éã§ããããã®ããå Unix ãã³ããŒã®ç¬èªã®ä¿®æ£ãä»ç€Ÿãåã蟌ãããšã¯ã§ããã䌌ããããªæ©èœãå®è£ ããã®ã粟äžæ¯ã§ãå®å šã«åãä»æ§ã§å®è£ ã§ããªãããäºææ§äžã®åé¡ãçºçããŸãããä»ã®ããã«ãªãŒãã³ãœãŒã¹ãåœããåã®äžçã«ãªãã®ã¯ 1990 幎代ã®åŸå以éã§ãã
æšæºåã¯ã³ã³ãã¥ãŒã¿ã¡ãŒã«ãŒã§ã¯ãªãã¢ããªã±ãŒã·ã§ã³éçºè ã«ãã£ãŠæšé²ãããŸãããPOSIX ã®å身ãšãªãæšæºåå£äœããŠãŒã¶ãŒã°ã«ãŒãã® /usr/group ã§ãã/usr/group 㯠1981 幎é ã«æšæºåå§å¡äŒãèšç«ããã1984 幎㫠/usr/group æšæºèŠæ Œãçå®ãããŸããããããããŸããŸãªçç±ã§ã¢ã¡ãªã«æ¿åºã /usr/group ãå ¬åŒã®æšæºåå£äœãšã¿ãªããªãã£ããããIEEE ã®ã¹ãã³ãµãŒã®ããšã§åå§åã 1988 幎ã«çå®ãããã®ã POSIX ã§ãããã®çµç·¯ããæšæž¬ããã«ã³ã³ãã¥ãŒã¿ã¡ãŒã«ãŒã¯ç§»æ€æ§ã®åäžã«ã¯ããŸãä¹ãæ°ã§ã¯ãªãã£ããšæãããŸããã ã£ãŠã¢ããªã±ãŒã·ã§ã³ãã©ã® Unix ã§ãåãã®ãªããä»ç€Ÿè£œã³ã³ãã¥ãŒã¿ã® Unix ã«ä¹ãæãããããªãã§ãããïŒ Unix ãã³ããŒã¯åœæã®ã¢ã¡ãªã«æ¿åºãçŽå ¥æ¡ä»¶ãšã㊠POSIX æºæ ïŒãã ã C èšèªã€ã³ã¿ãŒãã§ãŒã¹ã®ç¯å²ã§ã·ã§ã«ãã³ãã³ãã¯å«ãŸãªãïŒãæå®ããããã« POSIX ã«æºæ ããããåŸãªãã£ãã®ã ãšæãããŸããPOSIX æºæ ã¯ããã¯ãã㧠Unix æèŒã³ã³ãã¥ãŒã¿ã売ããšãã®ã¢ããŒã«ãã€ã³ãã«ã¯ãªããŸããã¢ã¡ãªã«æ¿åºã¯æ¬åœã¯ Unix ãæå®ãããã£ããããªã®ã§ããç¹å®ã®ãã³ããŒã«äŸåããªãæšæºèŠæ Œã¯ POSIX ã ãã§ããããã®çµæãWindows NT 㯠Unix ã§ã¯ãªãã«ãé¢ããã POSIX æºæ ãšããŠéçºããçŽå ¥æ¡ä»¶ãæºããããšã«ãªããŸããçµå±ã®ãšãã Windows NT 㯠POSIX æºæ ã§ããã Unix ã§ã¯ãªããã Unix ã®ä»£æ¿ã«ã¯ãªããŸããã§ãããçŸåšã® Windows ã«æèŒããã WSL 㯠POSIX æºæ ãè¶ ãã Linux äºææ©èœã§ãããããšãŠã人æ°ããããŸããã¡ãªã¿ã« POSIX ãã¢ã¡ãªã«æ¿åºã®çŽå ¥æ¡ä»¶ã ã£ãã®ã¯éå»ã®è©±ã§çŸåšã¯å»æ¢ãããŠããŸããåœæã®ã³ã³ãã¥ãŒã¿ã¡ãŒã«ãŒã Unix ã«ç¬èªæ©èœãæèŒããŠãã³ããŒããã¯ã€ã³ãç®æããŠããã®ã¯ããæå³æ£ããã£ãã®ãããããŸãããLinux ãš GNU ã³ãã³ãããããã POSIX ã«æºæ ããŠäœãã Unix ãã Linux ãžä¹ãæãããããããªã£ãçµæãçŸåšã® Linux ã®æ®åã«ã€ãªããåçš Unix ã®äžçã¯å€§ããè¡°éããããã§ãã
åéããããããã®ã§ãããPOSIX ã¯åœåãã UnixïŒé¢šã® OSïŒãäœãããã®æšæºèŠæ ŒãšããŠã¯äœãããŸããã§ãããPOSIX ã¯ã¢ããªã±ãŒã·ã§ã³ã®ç§»æ€ãçŠç¹ã§ãããPOSIX ãæ³å®ããŠãã OS ã«ã¯ Unix 以å€ã® OS ãå«ãŸããŠããŸããPOSIX 㯠Unix ãææ¬ã«ããŠäœãããŸããããUnix ãæã£ãŠããã·ã¹ãã 管çæ©èœïŒããŒããŠã§ã¢ç®¡çæ©èœããŠãŒã¶ãŒç®¡çæ©èœïŒã¯ã°ã£ããåé€ãããŠããŸãããããã®æ©èœã POSIX ã«å«ãŸããŠãããšãPOSIX ã«æºæ ããŠåãã¢ããªã±ãŒã·ã§ã³ãå¢ããããã ããªã®ã« Unix ãäœããªããã°ãªããªããªã£ãŠããŸããŸãããïŒ POSIX ã®ç¯å²ã§ã¯ã·ã¹ãã ã«ãã°ã€ã³ããæ©èœããŠãŒã¶ãŒãäœæããæ©èœããããŸããããããã¯ã¢ããªã±ãŒã·ã§ã³ãåããããã§æšæºåããå¿ èŠããªãããã§ããããããã·ã¹ãã 管çæ©èœã¯ã³ã³ãã¥ãŒã¿ã¡ãŒã«ãŒã販売ããåçš Unix ã«ãã£ãŠéãã®ãåœããåãªã®ã§æšæºåããããšæã£ãŠãã§ããŸãããPOSIX ã¯æšæºåã§ããªããã®ã¯æšæºåããŸãããç¹ã«ã°ã©ãã£ã«ã«ãŠãŒã¶ã€ã³ã¿ãã§ãŒã¹ãããŒã¿ããŒã¹ã€ã³ã¿ãŒãã§ãŒã¹ã¯æ確ã«å¯Ÿè±¡å€ãšèšèŒãããŠããŸããPOSIX ã®æ©èœã ãã§ã¯ãŸãšãã« Unix/Linux ã䜿ãããšãããã®äžã§åããœãããŠã§ã¢éçºã¯äžååãªã®ã§ãã
OS ã®æ©èœã¯å ããç°å¢äŸåãæ¿ããæ©èœã§ããã ããããïŒããçšåºŠã®ïŒæšæºåãå¿ èŠã«ãªããŸãããç¹å®ã® OS ã«äŸåããŠããªãå€ãã®ã³ãã³ããããã°ã©ãã³ã°èšèªã¯ POSIX ã®æšæºåã®å¯Ÿè±¡å€ã§ãããªããªã OS ã®æ©èœã§ã¯ãªãããã§ããPOSIX ã«ãšã£ãŠã¯ãããã¯ã¢ããªã±ãŒã·ã§ã³ã§ããå€ãã®ã³ãã³ããããã°ã©ãã³ã°èšèªã POSIX ã§æšæºåãããŠããªããããšèšã£ãŠãã·ã§ã«ã¹ã¯ãªããã C èšèªã䜿ããªããã° POSIX ã«æšæºããã¢ããªã±ãŒã·ã§ã³ãäœããªããšããããšã¯ãããŸãããã©ã®ãããªã³ãã³ããèšèªã䜿ã£ããšããŠãå éšã§ OS ã®æ©èœã䜿ãæã« POSIX ã€ã³ã¿ãŒãã§ãŒã¹ãåŒã³åºããŠããã° POSIX æºæ ã®ã¢ããªã±ãŒã·ã§ã³ãšèšããŸããäŸãã° curl ã jq ã SQLite 㯠POSIX ã³ãã³ãã§ã¯ãããŸããããPOSIX æºæ ã®ã³ãã³ãã§ç§»æ€æ§ãé«ãïŒã€ã³ã¹ããŒã«ããã°ïŒã©ã®ç°å¢ã§ã䜿ããã³ãã³ããšããŠæåã§ãããã®ãã㪠POSIX ã³ãã³ã以å€ã® POSIX æºæ ã³ãã³ããããã°ã©ãã³ã°èšèªãäœãããã«ãPOSIX æšæºèŠæ ŒãäœãããŸãããä»ã§ã¯ POSIX ã®ãããã§å€ãã®ã³ãã³ããããã°ã©ãã³ã°èšèªããããã OS ã§åãããã«ãªããããããå©çšããããšã§ç°¡åã«ã©ã®ç°å¢ã§ãåãã·ã§ã«ã¹ã¯ãªãããã¢ããªã±ãŒã·ã§ã³ãäœãããšãã§ããããã«ãªã£ãã®ã§ãã
POSIXã®æ¹å®å±¥æŽ
POSIX ã«é¢ããæšæºèŠæ Œã¯ããã€ãããæ··ä¹±ãããããããã«POSIXã®æ¹å®å±¥æŽããŸãšããŸããã
2000 幎é ãŸã§
åæã® POSIX ã®æšæºå㯠IEEE ã® PASC (Portable Application Standards Committee) ã«ãã£ãŠè¡ãããŠããŸãã
- PASC å ¬åŒãµã€ã
POSIX 㯠1988 幎ïŒC èšèªã€ã³ã¿ãŒãã§ãŒã¹ïŒãŸã㯠1992 幎ïŒã·ã§ã«ãšã³ãã³ãïŒã«æšæºåãããŠä»¥éãäœåºŠãæ©èœè¿œå ãå«ãæ¹å®ãè¡ãããŸãããåæã® POSIX èŠæ Œã¯ POSIX.nïŒãŸã㯠IEEE 1003.nïŒã®ãããªåœåèŠåã§ãããäŸãã° POSIX.1 ã Cèšèªã€ã³ã¿ãŒãã§ãŒã¹ãPOSIX.2 ãã·ã§ã«ãšã³ãã³ããšãã£ãæãã§ãããã㊠POSIX.1-1988 ã®ããã«åŸãã«ãã€ãã³ã§å¹Žå·ãä»ãããã®ãæšæºèŠæ Œã®ååã§ããããŸã POSIX.2 ãžã®è¿œå æ©èœã¯ POSIX.2a-1992 ã®ããã« n ã®ããšã«ã¢ã«ãã¡ããããä»å ãããŠããŸããããã®ãããªåœåèŠå㯠2000 幎é ãŸã§äœ¿ãããŸããããã®é ã® POSIX ã®æŽ»åã¯æŽ»çºã§ãæçµçã«ã©ããŸã§ã®æŽ»åãæ³å®ããŠããã®ãã¯ã£ãã調ã¹ãããŠããŸããããæ€çŽ¢ãããš POSIX.27ïŒC++ ãã€ã³ãã£ã³ã°ïŒã®ãããªãã®ãèšç»ã«ãã£ãããã§ãããã ããã®å€ããæ€åãããã POSIX.1 ã«åã蟌ãŸããŠæ¶ããŸããã
- PASC Status (including POSIX)
- åœæã®æšæºåã®ã¹ããŒã¿ã¹æ å ±ïŒæšæºèŠæ Œã®è©³çŽ°ãšæ°æ§ã®ååã®å¯Ÿå¿ãªã¹ãããïŒ
- https://collaboration.opengroup.org/external/pasc.org/standing/sd11.html
幎 | ã³ã¢æ©èœ | è¿œå æ©èœ | XPG / SUS âå¥ã®æšæºèŠæ Œâ | SVID |
---|---|---|---|---|
1984 | (/usr/group) | |||
1985 | XPG1 (Issue 1) | SVID1 | ||
1987 | XPG2 (Issue 2) | SVID2 | ||
1988 | POSIX.1-1988 | |||
1989 | XPG3 (Issue 3) | SVID3 | ||
1990 | POSIX.1-1990 | |||
1992 | POSIX.2-1992 | POSIX.2a-1992 | XPG4 (Issue 4) | |
1993 | POSIX.1b-1993 | |||
1994 | POSIX.2d-1994 | XPG4v2 (Issue 4 version 2) | ||
1995 | POSIX.1c-1995 | SUSv1 (UNIX 95) | SVID4 | |
1996 | POSIX.1-1996 | |||
1997 | SUSv2 (UNIX 98, Issue 5) | |||
1998 | POSIX.13-1998 | |||
1999 | POSIX.1d-1999 | |||
POSIX.2b draft | ||||
2000 | POSIX.1g-2000 | |||
POSIX.1j-2000 | ||||
POSIX.1q-2000 |
POSIX ã¯ç¹å®ã® Unix ãã³ããŒã®ããã®æšæºèŠæ Œã§ã¯ãããŸãããäžç«çã§åœæã®äºå€§ Unix ã§ãã£ã BSD Unix ãš UNIX System V ã®äž¡æ¹ãèæ ®ããŠäœãããæšæºèŠæ Œã§ããäž¡æ¹ãèæ ®ããŠããã®ã§ããã°ãPOSIX ã«æºæ ããã° BSD Unix ãš UNIX System V ã®äž¡æ¹ã§åãããã«ãªããšæããããããŸããããçµå±ã®ãšããäž¡æ¹ã«å ±éãããã®ããæšæºåãã§ããªããšããããšãªã®ã§ãPOSIX ã§æšæºåãããç¯å²ã§ã§ããããšã¯å°ãªããªããŸããæšæºèŠæ Œã¯ POSIX ã ãã§ã¯ãããŸãããXPG (X/Open Portability Guide) 㯠X/Open ãšããå£äœã«ããæšæºèŠæ Œã§ããX/Open 㯠POSIX ãããåºãç¯å²ã®æè¡ã察象ã«ããŠããããã®ç¯å²ã«ã¯äŸãã° SQL ããŠã€ã³ããŠã·ã¹ãã ãªã©ãå«ãŸããŠããŸãããã ã X/Open ãæšæºèŠæ Œã®ãã¹ãŠãäžããçå®ããŠãããšããããã§ã¯ãªããä»ã®æšæºèŠæ Œãåç §ããŠäœãããŠããŸããXPG4 ã®äžã®äžéšã§ããåºæ¬ä»æ§ã¯ X/Open CAE Specification (CAE = Common Applications Environment) ãšåŒã°ããŠãããPOSIX ã®æšæºåã®ç¯å²ã«è¿ã C èšèªã€ã³ã¿ãŒãã§ãŒã¹ãã·ã§ã«ãã³ãã³ããªã©ãããã¥ã¡ã³ãåãããŠããŸãã
X/Open 㯠AT&T ãã Unix ã®æš©å©ãè²·ãåã£ã Novell ãã Unix ãã©ã³ããè²æž¡ãããä»ã®å£äœãšã®å䜵ãªã©ãçµãŠ The Open Group ãšååãå€ããçŸåšã¯ SUS (Single UNIX Specification) ãšããæšæºèŠæ Œãçºè¡ããŠããŸãããã® SUS ã Unix ã§ãããšèªããããããã«å¿ èŠãªæšæºèŠæ Œã§ããäŸãã° SUSv1 ã«èªå®ããã Unix 㯠UNIX 95 ãšãããã©ã³ãåãåä¹ãããšãã§ããŸããSUS 㯠X/Open CAE Specification ã®åŸç¶ãšããŠãã®ããã¥ã¡ã³ãã®äžéšããæ§æãããŠããŸããã€ãŸã XPG ã¯å¹ åºãæè¡ã察象ãšããŠããŸããããSUS ã®å¯Ÿè±¡ãšããç¯å²ã¯ãããããå°ãã POSIX ã®å¯Ÿè±¡ç¯å²ãå°ãè¶ ããçšåºŠã«è¿ã¥ããŸãããã¡ãªã¿ã« XPG 㯠OS ã®ã€ã³ã¿ãŒãã§ãŒã¹ãšã㊠SVID (System V Interface Definition) ãšããå¥ã®æšæºèŠæ Œãåç §ããŠãããSVID ã¯ãã®åã®éã UNIX System V ã®ã€ã³ã¿ãŒãã§ãŒã¹ãå®çŸ©ãã AT&T ãçå®ããæšæºèŠæ Œã§ãããã®ãã XPG ãš SUS ã§æšæºåããã OS ã®ã€ã³ã¿ãŒãã§ãŒã¹ã¯ System V ç³» Unix ã«è¿ããã®ãšãªã£ãŠããŸãã
2000 幎以é
POSIX ã¯å 㯠IEEE ã«ããæšæºèŠæ Œã§ãããçŸåšïŒ1997幎以éïŒã¯ POSIX ã®æ¹å®äœæ¥ãè¡ãããã«èšç«ãããå ±åæè¡ã¯ãŒãã³ã°ã°ã«ãŒãã§ãã Austin Group ã«ãã£ãŠæ¹å®äœæ¥ãè¡ãããŠããŸããPOSIX ãšåŒã°ããŠããæšæºèŠæ Œã¯ãIEEE (PASC)ãISO/IEC (JTC 1/SC 22)ãThe Open Group ã®3ã€ã®å£äœãããããçºè¡ããŠããæšæºèŠæ Œã®ããŒã¹ãšããŠæ¡çšããŠãããããããã®çµç¹ã®ã¡ã³ããŒã Austin Group ã«åå ããŠããŸããAustin Group ã®è°é·ã¯ The Open Group ã® Andrew Josey ã§ããã¡ãªã¿ã« Austin Group ãžã¯èª°ã§ãç¡æã§åå ã§ããïŒã¡ãŒãªã³ã°ãªã¹ããžã®ç»é²ãå¿ èŠïŒã®ã§ã誰ã§ã POSIX ã®æšæºèŠæ Œã®å 容ã«å£ãåºãããšãã§ããŸãããã¡ããå Unix/Linux ã®é¢ä¿è ã§åå ããŠãã人ãããã¯ãã§ãã誰ã§ãæ°ããæšæºèŠæ Œã POSIX ã«ææ¡ããããšãã§ããŸãããçºæãïŒä»ãŸã§ã«èª°ãå®è£ ããããšããªãçŽ æŽãããæ°æ©èœïŒã¯æ¡çšãããªãããšã«æ³šæããŠãã ãããPOSIX ã®æšæºåãšã¯æ°ããæ©èœãäœãããšã§ã¯ãªããæ¢åã®å®è£ ã®åäœãææåããããšã§ãã
SUS ã¯å 㯠POSIX ãšã¯ç¬ç«ããæšæºèŠæ Œã§ããããAustin Group ã«ãã£ãŠ POSIX ãšã®çµ±åäœæ¥ãè¡ãããPOSIX.1-2001 㧠POSIX æšæºèŠæ Œã®æ¡åŒµèŠæ ŒãšããŠçµ±åãããŸãããIEEE ãçºè¡ããæšæºèŠæ Œã¯ææã§ãããThe Open Group 㯠SUS ãšããŠç¡æã§å ¬éããŠãããPOSIX ãšçµ±åããã SUS ãšãã圢ã§ç§éã¯ç¡æ㧠POSIX æšæºèŠæ Œæžãåç §ããããšãã§ããŸããSUS ã®ã¿ã«ååšããŠããæ©èœã¯ãXSI ãªãã·ã§ã³ãšåŒã°ããæ¡åŒµæ©èœãšããŠãPOSIX ã«æºæ ããã ããªãå®è£ ã¯å¿ é ã§ã¯ãªãä»æ§ããšããŠèšèŒãããŠããŸãããŸã SUS ã«ã¯ POSIX ã«ã¯çµã¿èŸŒãŸããªãã£ã X/Open Curses ãšãã£ãä»æ§ããããŸããPOSIX ã«å«ãŸããŠãã XSI ãªãã·ã§ã³ã¯å 㯠UNIX System V ã®ä»æ§ã§ããSUS ã Unix ãšèªããããããã«æºãããªããã°ãããªãä»æ§ãšã¯ïŒBSD Unix ã§ã¯ãªãïŒUNIX System V ãšã®äºææ§ãå®çŸããããã®ä»æ§ã§ããããšãæå³ããŠããŸããèšãæãããš XSI ãªãã·ã§ã³ã¯ BSD ç³» Unix ãšã®äºææ§ãäœãéšåã§ããBSD ç³» Unix ã§ã¯ XSI ãªãã·ã§ã³ã¯å®è£ ãããŠããªãå¯èœæ§ãããã ãã§ã¯ãªããæšæºåãããå 容ãšã¯ç°ãªãä»æ§ã§å®è£ ãããŠããå¯èœæ§ããããŸããXSI ãªãã·ã§ã³ãäœããç¥ããªããšãPOSIX æšæºèŠæ Œã«ïŒXSI ãªãã·ã§ã³ãšããŠïŒèšèŒãããŠããã®ã ãã移æ€æ§ãããæ©èœãªã®ã ããåéãããã¡ã§ãããXSI ãªãã·ã§ã³ã®éšåã¯ç§»æ€æ§ããªããããããªãæ©èœãªã®ã§ããUbuntu ã®ãšããããŒãžã«ã¯ãããããŸãã
We recommend that developers of shell scripts adhere to the POSIX standard, omitting those items flagged as XSI extensions.
èš³ ç§éã¯ã·ã§ã«ã¹ã¯ãªããã®éçºè ãã¡ã¯ POSIX æšæºã«æºæ ããXSI æ¡åŒµãšããŠãã©ã°ãã€ããããé ç®ãçç¥ããããšãããããããŸãã
POSIX.1-2001 以éã§ã¯åŸæ¥ã® POSIX.n ãšããåœåèŠåãã»ãŒãªããªããPOSIX.2 㯠POSIX.1 ã«çµ±åãããŸãããã€ãŸãçŸåšã® POSIX æšæºèŠæ Œã¯ POSIX.1-xxxx ãšããåœåèŠåã®ã¿ã§ãïŒãªã¢ã«ã¿ã€ã ã³ã³ãããŒã©ãŒã·ã¹ãã ã®ãããã¡ã€ã«ãå®ãã POSIX.13 ãé€ãïŒããã®é ã«ã¯ãã POSIX ã®éçºã¯ã¡ã³ããã³ã¹ã®ãããªãã®ãšãªã倧ããªæ©èœè¿œå ãè¡ããšããèãã¯ãªããªã£ãŠããããã§ããUNIX ã®æšæºèŠæ Œã¯ POSIX ã®æšæºèŠæ Œã«å¯Ÿå¿ã㊠SUSv3ãSUSv4 ã®ãããªååãšãªã£ãŠããŸããSUS ã POSIX ã«çµ±åããã POSIX.1-2001 (SUSv3) ã®æç¹ã§ã¯å€ãã® XSI ãªãã·ã§ã³ããããŸããããPOSIX.1-2008 (SUSv4) ã§ã¯å€ãã® XSI ãªãã·ã§ã³ãæšæºæ©èœãžãšå€æŽã«ãªã£ãŠããŸããããã¯å ã UNIX System V ãšã®äºææ§ã®ä»æ§ã ã£ããã®ã BSD ç³» Unix ã Linux ã§ãå®è£ ãããŠã移æ€æ§ããããã XSI ãªãã·ã§ã³ãšããå¿ èŠããªããªã£ãããšãæå³ããŠããŸããéã«èšãã°çŸåšã XSI ãªãã·ã§ã³ã®ãŸãŸæ®ã£ãŠãããã®ã¯ç§»æ€æ§ã«é¢ããŠããã«æ³šæãå¿ èŠã ãšããããšã§ãã
Year | æšæºèŠæ Œ | 现ããä¿®æ£ç | SUSïŒPOSIX ã«çµ±åãããæ¡åŒµèŠæ ŒïŒ |
---|---|---|---|
2001 | POSIX.1-2001 | SUSv3 (UNIX 03, Issue 6) | |
2003 | POSIX.1-2001 TC1 | : 2003 Edition | |
2004 | POSIX.1-2001 TC2 | : 2004 Edition | |
2008 | POSIX.1-2008 | SUSv4 (UNIX V7, Issue 7) | |
2013 | POSIX.1-2008 TC1 | : 2013 Edition | |
2016 | POSIX.1-2008 TC2 | : 2016 Edition | |
2017 | POSIX.1-2017 | : 2018 Edition | |
2024 | POSIX.1-2024 | SUSv5ïŒä»®ïŒ (UNIX V8, Issue 8) | |
: | |||
20xx | POSIX.1-20xx | SUSv6ïŒä»®ïŒ (UNIX V9, Issue 9) |
现ããä¿®æ£ç (TC: Technical Corrigendum) ã§ã¯ãæšæºèŠæ Œã®ééãã®èšæ£ãè¡ã£ãããå°æ¥ã®å€§èŠæš¡ãªæšæºèŠæ Œã®æ¹å®ã§è¡ããããããããªãå 容ããå°æ¥ã®æ¹åæ§ã(FUTURE DIRECTIONS) ã«è¿œèšãããããŠããŸãããå°æ¥ã®æ¹åæ§ããå®çŸããã«ã¯åUnix/Linuxã®å®è£ è ããã®æ¹åæ§ã«åæããŠå®è£ ããªããã°ãããªãã®ã§å¿ ãããå®çŸãããšã¯éããŸããããããŸã§ POSIX ãèããŠããå°æ¥åã§ããPOSIX.1-2017 㯠2018 幎ã«æšæºèŠæ Œãæéåãã«ãªãã®ãé²ãããã«å ¬éãããæ¹å®çã§ããå³å¯ã«ã¯ä»åã®æ¹å®ã§ãã POSIX.1-2024 ã®äžã€å㯠POSIX.1-2017 ã«ãªãã®ã§ãããPOSIX.1-2017 ã®å 容㯠POSIX.1-2008 2016 Edition (POSIX.1-2008 + TC1 + TC2) ãšåäžã§ããããæ¬èšäºã§ã¯å€§å¹ ãªæ¹å®ã«ã¯å«ããŠããããä»åã®æ¹å®ã¯ 16 幎ã¶ãã®å€§å¹ ãªæ¹å®ãšããããšã«ãªããŸãã
ã¡ãªã¿ã« Austin Group ã§ã¯ POSIX æšæºèŠæ Œã®åããŒãžã§ã³ã¯ã³ãŒãããŒã ã®ãããªæã㧠Issue N ã®ãããªååã§åŒã°ããŠããŸãããã㯠The Open Group ã®å身ã§ãã X/Open æ代ããç¶ç¶ããŠããååã§ãïŒXPG1 = Issue 1ïŒã现ããæ¹èšçã¯åºå¥ããããšãªã Issue N ãšåŒã°ããŠãããæ£åŒãªæšæºèŠæ Œã®ååã䜿ããããããããããã§ãã次åïŒ10幎åŸãããïŒïŒã®æ¹å®ç㯠Issue 9 ãšåŒã°ããŠããŸããIssue N ã¯æšæºèŠæ Œã® CHANGE HISTORY ã§ã®æ¹å®å±¥æŽãªã©ã§ã䜿ãããŠããŸããã¡ãªã¿ã« Solaris 11 ã§ã¯ /usr/xpg4/binã/usr/xpg6/binã/usr/xpg7/bin ã®ãããªãã£ã¬ã¯ããªã«ããããã®æšæºèŠæ Œã®ããŒãžã§ã³ã«é©åããã³ãã³ããã€ã³ã¹ããŒã«ãããŠããŸãããxpg6 ã xpg7 ã®ãããªå称ã¯æšæºèŠæ Œã®ååãšããŠã¯æ£ç¢ºãªãã®ã§ã¯ãããŸããã
ãªãOSæšæºã³ãã³ãã¯å å®ããªãã®ãïŒ
ãããŸã§èªãã§ããã人ãªããã§ã«æ°ã¥ããŠãããšæããŸãããUnix/Linux ã® OS æšæºã³ãã³ãã䟿å©ã§å å®ããç©ã«ãªããªãã®ã¯ãOS ã®éçºè ãããããäœãå¿ èŠããªãããã§ããPOSIX ã®ç§»æ€æ§ã®èŠã¯ C èšèªã€ã³ã¿ãŒãã§ãŒã¹ã§ããUnix/Linux ã® OS ã®éçºè ããããã° C èšèªã€ã³ã¿ãŒãã§ãŒã¹ããæšæºåãããŠããã°ããã䜿ã£ãŠèª°ã§ãããŸããŸãªã¢ããªã±ãŒã·ã§ã³ãäœããããã§ãèªåãã¡ã§ OS ã®ã³ãã³ããå å®ãããå¿ èŠããããŸããã
OS æšæºã³ãã³ã㯠OS ã®äžéšã§ããããç°å¢äŸåãæ¿ãããªãããããšããåé¡ããããŸããç¹ã« BSD ç³» Unix ã System V ç³» Unix ã§ã¯ OS ã«çµã¿èŸŒãŸããã³ãã³ãã¯ãããããå¥ã ã«éçºããŠããããšããåŸåã«ãããŸããïŒããã€ãã®äŸå€ããããŸããïŒã³ãŒãã®ä¿®æ£ãäžæµã®ãããžã§ã¯ãã«éã㊠OS ãšã¯ç¬ç«ããŠè²ãŠãŠããããšã¯ããŸãããå ã OS ã®éçºãšããã®ã¯ãããããã®ã§ããPOSIX 㧠OS ã®ã€ã³ã¿ãŒãã§ãŒã¹ãæšæºåããããšèšã£ãŠããPOSIX ã OS ã®ä»æ§ãäœã£ãŠããããã§ã¯ãªãããã1990 幎代以éã® OS ã®éçºã¯ãããããã® OS ã§ç¬ç«ããéçºã§ãã
å OS ã®éçºè ã¯ãèªåãã¡ã«ãšã£ãŠå¿ èŠãªã³ãã³ãã®å®è£ ã¯è¡ããŸãããã©ã®ç°å¢ã§ãåã移æ€æ§ã®ããæ°ãã OS ã®ã³ãã³ããã¿ããªã§äœã£ãŠããããšããèãã¯æã£ãŠããŸããïŒäººã«ãããšã¯æããŸããïŒãããããæ¢åã®ã³ãã³ãã«è¿œå ããæ©èœããä»ã® Unix/Linux ã®ã³ãã³ããç䌌ããŠå®è£ ããçšåºŠã§ãã移æ€æ§ãããæ°ãã OS ã®ã³ãã³ããå å®ããªãã®ã ãã POSIX ã§æ°ããã³ãã³ããæšæºåãããããšããããŸãããä»åã®å€§å¹ ãªæ¹å®ã§ãå®éã«ã¯äœå¹Žãåããã©ããã§å®è£ ãããŠããæ©èœã倧åã§ããæšæºåãããã®ã¯é·ãæéããããŠã©ã®ç°å¢ã§ã䜿ããããã«ãªã£ã移æ€æ§ã®ããããããªã³ãã³ããæ©èœã ãã§ãã
ã·ã§ã«ã¹ã¯ãªããã®åéãã»ãšãã© 1990 幎é ã®ãŸãŸã§çºå±ããŠããªãã®ã¯ãPOSIX ã§æšæºåããã OS ã®ã³ãã³ãã¯æšæºåãããŠããããè¯ããã®ãªãã§ããïŒãšããèããã移æ€æ§ãé«ãã³ãã³ããã€ã³ã¹ããŒã«ããã®ãé¢åã ãããšæåãã䜿ããã³ãã³ãã§ããã ãã䜿ã£ãŠã·ã§ã«ã¹ã¯ãªãããæžãã®ãè¯ãããšã ãšããééã£ãèããåºãŸã£ãŠããããã§ããOS æšæºã³ãã³ãã¯ãããããå å®ããããšã¯ãããŸãããåŸæ¹äºææ§ãç¶æããããã«å€§ããæ¹è¯ãããããšã¯ãããŸããããããã£ãŠäººé¡ãç®æãã¹ããªã®ã¯è± POSIX ã³ãã³ãã§ããPOSIX ã³ãã³ãããªããªãããšã¯ãããŸããããã€ãŸã§ãäžäŸ¿ãªãŸãŸãªã®ã§ããããå©çšããŠã·ã§ã«ã¹ã¯ãªãããæžãã®ã¯ãç¹å®ã® OS ã«äŸåããã·ã§ã«ã¹ã¯ãªãããäœããšãã ãã§ååã§ããäžè¬ã®ããã°ã©ã㯠POSIX ãæèããå¿ èŠããªãããŠããã¹ãã§ããå°æ¥çã« POSIX ãæèããå¿ èŠããªããããã«ãä»ã¯ãŸã æäœéïŒå®ç§ã§ã¯ãªãã䟿å©ãšããæå³ïŒã®ç§»æ€æ§ã解説ãã POSIX ãç¥ãå¿ èŠããããŸãã
ã·ã§ã«ã¯äœãå€ãã£ããïŒ
æåã«èª¬æããéãã·ã§ã«ãå€ãã£ããšèšã£ãŠãããã¯ãããŸã§POSIXã§æšæºåãããŠããã·ã§ã« (POSIX sh) ãå€ãã£ããšãã話ã§ããè¿œå ãããæ©èœã¯ãã§ã« bash ã ksh ãªã©ã§å®è£ æžã¿ã§ã人ã«ãã£ãŠã¯ããªãã¿ã®æ©èœã°ããã§ãã
ã·ã§ã«èšèªèªäœã®æ©èœ
ããã§ã¯ã·ã§ã«èšèªèªäœã«è¿œå ãããæ©èœã玹ä»ããŸãã
ANSI C æååã解éãã $'...'ïŒãã©ãŒã·ã³ã°ã«ã¯ã©ãŒãïŒã®è¿œå
$'...'
ïŒãã©ãŒã·ã³ã°ã«ã¯ã©ãŒãïŒã¯ ANSI C ã®ããã¯ã¹ã©ãã·ã¥ãçšãããšã¹ã±ãŒãã·ãŒã±ã³ã¹ã解éããæååã§ãã
$ printf '%s\n' $'Hello\nWorld'
Hello
World
bashãksh93ãzshã¯ããªãæãã察å¿ããŠããŸããFreeBSD shãšNetBSD sh ã¯ææ°çã§ã¯å¯Ÿå¿ããŠããŸãããã ã dash ã OpenBSD sh ã§ã¯ãŸã 察å¿ããŠããŸããããããããã®ãã¡å¯Ÿå¿ããã§ãããã
2023-06-23 è¿œèš dashã« $'...'
ã®æ©èœã 2024-06-22 ã«è¿œå ãããŸããããããã v0.5.13 以éã§å¯Ÿå¿ããããšã§ãããããŸããã«ããã€ãæåãžã®å¯Ÿå¿ãè¡ãããŠããŸãã
察å¿ããŠããªãã·ã§ã«ã§ã¯ printf
ã³ãã³ãã䜿çšããŠãšã¹ã±ãŒãã·ãŒã±ã³ã¹ã解éããããšãã§ããŸãããå€æ°ã«ä»£å
¥ãããã³ãã³ãã®åŒæ°ã«äœ¿çšããå Žåã¯ãµãã·ã§ã«ã䌎ãã³ãã³ã眮æã䜿çšããå¿
èŠãããããé
ããªããŸãããã©ãŒã·ã³ã°ã«ã¯ã©ãŒãã¯ãã®ãããªåé¡ã解決ãããã®ã§ãã
äœè«ã§ããã $'...'
㯠tcsh ã§ã 2022幎2æ2æ¥ã«ãªãªãŒã¹ããã 6.24.00 以éã§å¯Ÿå¿ããŠããŸãã
case ã®ãã©ãŒã«ã¹ã«ãŒ (;&) ã®è¿œå
å€ãã®ã·ã§ã«ã察å¿ããŠãããcase
ã³ãã³ãã®ãã©ãŒã«ã¹ã«ãŒ (;&
) ãæšæºåãããŸããã以äžã®ã³ãŒãã¯ãfoo ãš bar ã®äž¡æ¹ãåºåããŸãã
case foo in
*foo*) echo foo ;& # 次ã®è¡ã®ã³ãã³ããå®è¡ããã
*bar*) echo bar ;; # bar ã«ã¯ãããããŠããªããå®è¡ããã
esac
ã¡ãªã¿ã« bash ã¯ãã©ãŒã«ã¹ã«ãŒã«äŒŒãŠããã次ã®æ¡ä»¶å€å®ãè¡ã ;&&
ãå®è£
ãããŠããŸããããã¡ã㯠POSIX ã§ã¯æšæºåãããŠããŸããããããã ksh ãš zsh ã§å®è£
ãããŠããªãããåè£ã«ãªããªãã£ãã®ã§ã¯ãªãããšèããããŸãã
åèªåå²ãIFS ã®ä»æ§ã詳现ã«å®çŸ©ããã
ä¿¡ããããªãããšã«ãããŸã§åèªåå²ããŸã㯠IFS
ã·ã§ã«å€æ°ã®ä»æ§ãæããã«äžååã§ãããPOSIX.1-2024 ã§ã¯è©³çŽ°ã«å®çŸ©ãããŠãããæžãçŽãã«è¿ãã¬ãã«ã§ããªãã®éã®æç« ãè¿œå ãããŠããŸãã
ã©ãã㧠POSIX çºããŠããŠã IFS
ã®çŽ°ããä»æ§ããããããã£ãã¯ãã ã......
ã¯ã©ãŒããæšå¥šããæåã®å€æŽ
ã·ã§ã«èšèªã¯æåãã¯ã©ãŒãããã«ãã®ãŸãŸæžãããšãã§ããŸãããäžéšã®æåïŒèšå·ïŒã¯ã¯ã©ãŒãããã«äœ¿ããšç¹å¥ãªæå³ãæã¡ãŸããå€ãã®æåãã¯ã©ãŒããå¿ èŠã«ãªã£ãŠãããããéã«ã¯ã©ãŒãããã«äœ¿ããæåãäŸç€ºããã»ããç°¡åã§ããããã«æããèšå·ä»¥å€ã¯ã¯ã©ãŒãããããšãæšå¥šããŸãããããããªããã°èšå·ã¯ãã¹ãŠã¯ã©ãŒãããæ¹éã§ãããã§ãããã
+ - . / : @ _
å®è£ ãå¿ é ã§ã¯ãªããã¬ãŒã¹å±éãžã®èæ ®
äžéšã®ã·ã§ã«ã¯ãã¬ãŒã¹å±éïŒ{1..10}
ã {a,b,c}.txt
ã®ãããªãã®ïŒãå®è£
ããŠããŸããããããŸã§ã® POSIX ã§ã¯ææ³çã«åãå
¥ããããŠããŸããã§ããããã®æ¡åŒµæ©èœã®å®è£
ãå¯èœã«ãªãããã«ææ³ãä¿®æ£ãããŸããããŸãããã¬ãŒã¹å±éããµããŒãããŠããã·ã§ã«ã§ã¯ãã¹ãŠã®æšæºçãªåèªå±éã®åã«å®è¡ãã¹ãã§ããããšæèšãããŸããããã¬ãŒã¹å±éããã®ä»ã®å±éã®ãããåŸã«å®è¡ããããšäºæãã¬çµæãããããå¯èœæ§ãããããã§ãã
$ zsh -c 'a="1." b=".10"; echo {$a$b}'
1 2 3 4 5 6 7 8 9 10
bash ã POSIX ã¢ãŒãã® ksh93u+m ã§ã¯ POSIX ã§æšæºåãããŠããéããã¬ãŒã¹å±éã¯æåã«è¡ãããã®ã§ããã®ãããªäºæãã¬çµæã¯çºçããŸããããã ã次ã®ããã«æ°å€ã®çµäºå€ã«å€æ°ã䜿ããªããªã©äžäŸ¿ã«æããå ŽåããããŸãããã®åé¡ã¯ eval
ã³ãã³ãã䜿ã£ãŠåé¿ããããšãã§ããŸãã
$ bash -c 'n=10; echo {1..$n}'
{1..10}
$ ksh -o posix -c 'n=10; echo {1..$n}' # ksh93u+mïŒksh93ã¯é察å¿ïŒ
{1..10}
$ bash -c 'n=10; eval "echo {1..$n}"'
1 2 3 4 5 6 7 8 9 10
POSIX ã¢ãŒãã§ã¯ãªã ksh ã zsh ã§ã¯æ¬¡ã®ãããªåäœã«ãªããŸãã
$ ksh -c 'n=10; echo {1..$n}'
1 2 3 4 5 6 7 8 9 10
$ zsh -c 'n=10; echo {1..$n}'
1 2 3 4 5 6 7 8 9 10
ç¹°ãè¿ããŸããããããŸã§ä»æ§ãå®çŸ©ãããŠããªããããã¬ãŒã¹å±éã®å®è£ 㯠POSIX.1-2024 ã§ã¯å¿ é ã§ã¯ãããŸããããã ããã¬ãŒã¹å±é㯠POSIX ã§æåŠãããŠããããã§ã¯ãªãã誰ãæšæºèŠæ ŒãæžããŠãããã詳现ãªè°è«ïŒè€æ°ã®ã·ã§ã«ã®åäœãççŸãªãå ±éã®æç« ã§å®çŸ©ã§ãããïŒãè¡ãããŠããªããšããã ããªã®ã§ãå°æ¥ã® POSIX ã§æšæºåãããå¯èœæ§ãé«ãæ©èœãšèããããŸãã
å®è£ ãå¿ é ã§ã¯ãªã {fd}>file ãžã®èæ ®
bash ãš ksh ã§å¯Ÿå¿ããŠãããã¡ã€ã«ãã£ã¹ã¯ãªãã¿çªå· 10 以äžãæ±ãããã®ä»¥äžã®ãããªæ§æãèš±å¯ãããŸããã
( echo "[fd: $fd] test" >&"$fd" ) {fd}>/tmp/log.txt
ãã®æ©èœã POSIX.1-2024 ã§ã¯ãªãã·ã§ã³æ©èœã§ããå®è£ ã¯å¿ é ã§ã¯ãããŸããããæ¡åŒµæ©èœãšããŠå®è£ ããŠã POSIX ã«éåããªãããã«ææ³ãèš±å¯ãããŠããŸãã
å°æ¥ã®æ¹åæ§: ã.*ããã.ãã..ãã«å±éããªãããã«ãªã
çŸåšã®ã·ã§ã«ã®å®è£
ã§ã¯ .*
ã .
ãš ..
ã«å±éãããå Žåãšå±éãããªãå ŽåããããŸããå€ãã®ã·ã§ã«ã§ã¯ããã©ã«ã㧠.
ãš ..
ã«å±éãããŸãããbash 5.2以éãkshãmkshãzsh ã§ã¯å±éãããŸããã
$ echo .*
. . .file.txt
$ echo .*
.file.txt
ãã¹åäžèŠ§ã« .
ãš ..
ãå«ãŸããããšã«æå³ã¯ãªãããã°ã®åå ã«ãªããšããŠãPOSIX.1-2024 ã§ã¯ã.
ãš ..
ãç¡èŠããå Žåãããããšæèšãããå°æ¥ã®ããŒãžã§ã³ã§ã¯ã.
ãš ..
ãç¡èŠããããšãèŠæ±ãããããããªããããšãèšèŒãããŸããã
bash 㯠5.2 以éã§ããã©ã«ã㧠.
ãš ..
ã«å±éãããªããªããŸããããã®ãããããã .
ãš ..
ã«å±éãããã·ã§ã«ãããããšã«æ°ã¥ãã«ãããªããŸãã.
ãš ..
ã«å±éãããªãã®ã¯æ¹åæ§ãšããŠã¯æ£ãããšæããŸããã移æ€æ§ãããã·ã§ã«ã¹ã¯ãªãããæžãããšãã人ã«ãšã£ãŠã¯ããã®ä»æ§ã«æ°ã¥ããªãããšã«ãããã°ãçºçããå¯èœæ§ããããŸãããªã以åã®åäœã«æ»ãã«ã¯ shopt -u globskipdots
ãå®è¡ããŸãã
è£è¶³ã§ãããls -a
㧠.
ãš ..
ãå«ãé ããã¡ã€ã«ãšéåžžã®ãã¡ã€ã«ã®äžèŠ§ãåºåããããšãã§ããŸãããls -A
ã䜿çšããã° .
ãš ..
ãç¡èŠããããšãã§ããŸãã-A
ãªãã·ã§ã³ã¯ POSIX.1-2008 ã§æšæºåãããŠããŸãã
ã³ãã³ãã®åé¡ã®è©³çŽ°å
ã·ã§ã«ã«çµã¿èŸŒãŸããã³ãã³ãã¯ããããŸã§ãç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãããšãéåžžã®ã·ã§ã«ãã«ãã€ã³ã³ãã³ããã®2ã€ã®åé¡ãããããŸããã§ããããã®åé¡ã¯ä»ãå€ãã£ãŠããŸãããã宣èšã³ãã³ããšå åšã³ãã³ããšããæ°ããªåé¡ãè¿œå ãããŸãããã·ã§ã«ã«çµã¿èŸŒãŸããã³ãã³ãã¯ãç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãããå åšã³ãã³ãããéåžžã®ã·ã§ã«ãã«ãã€ã³ã³ãã³ããã®ããããã«åé¡ããããã®äžã«ã宣èšã³ãã³ããã«è©²åœããã³ãã³ãããããšããé¢ä¿ã§ãã
宣èšã³ãã³ã (Declaration Utilities)
宣èšã³ãã³ããšã¯ãå€æ°ãžã®ä»£å
¥ãè¡ã圢ã«ãªã£ãŠããã¿ã€ãã®ã³ãã³ããã§ãPOSIX ã§ã¯ export
ãreadonly
ãç¹å¥ãªå Žåã® command
ã宣èšã³ãã³ããšããŠå®çŸ©ãããŠããããã®ä»ã«å®è£
ãè¿œå ã®å®£èšã³ãã³ããæäŸããŠããå ŽåããããŸãïŒdeclare
ã typeset
ã local
ãªã©ïŒ
宣èšã³ãã³ããšããåºå¥ãå¿ èŠãªçç±ã¯éåžžã®ã³ãã³ãåŒã³åºããšå®£èšã³ãã³ãã§åŒæ°ã®è§£éãç°ãªãããã§ããå ·äœçãªäŸãèŠãŠãããŸãããã
$ var='123 VAR2=456'
$ env VAR1=$var sh -c 'echo "$VAR1 : $VAR2"'
123 : 456
$ var='123 VAR2=456'
$ export VAR1=$var && sh -c 'echo "$VAR1 : $VAR2"'
123 VAR2=456 :
ã©ã¡ããç°å¢å€æ°ã«å€ãèšå®ããŠãã®å€ãåºåããã³ãŒãã§ããçµæãç°ãªã£ãŠããŸããããã¯åèªåå²ã«ããæåã®éãã§ããéåžžã®ã³ãã³ãã¯å€æ°ãåç
§ãããšãã«ããã«ã¯ã©ãŒããããŠããªãå Žåã¯åèªåå²ãè¡ãããŸããã€ãŸãã¹ããŒã¹ïŒæ£ç¢ºã«ã¯ IFS
ã·ã§ã«å€æ°ã§æå®ãããæåïŒã§åå²ããè€æ°ã®åŒæ°ãçæãããŸãããã®ããåè
ã® env
ã³ãã³ãã®äŸã¯æ¬¡ã®ããã«è§£éãããŸãã
$ var='123 VAR2=456'
$ env VAR1=$var sh -c 'echo "$VAR1 : $VAR2"'
â
$ env VAR1=123 VAR2=456 sh -c 'echo "$VAR1 : $VAR2"'
äžæ¹ã§å®£èšã³ãã³ãã®å Žåã¯åèªåå²ãè¡ãããŸãããã€ãŸãåŸè
ã® export
ã³ãã³ãã®å Žåã¯æ¬¡ã®ããã«è§£éãããŸãã
$ var='123 VAR2=456'
$ export VAR1=$var && sh -c 'echo "$VAR1 : $VAR2"'
â
$ export VAR1='123 VAR2=456' && sh -c 'echo "$VAR1 : $VAR2"'
ã¡ãªã¿ã«åèªåå²ãè¡ãããªãã®ã¯éåžžã®å€æ°ä»£å ¥ã§ãåãã§ãã
$ var="123 VAR2=456"
$ VAR1=$var && echo "$VAR1 : $VAR2"
123 VAR2=456 :
ã€ãŸãå€æ°ãžã®ä»£å ¥ã®åœ¢ããã宣èšã³ãã³ãã¯ãéåžžã®å€æ°ãžã®ä»£å ¥ãšåãæåããããšããããšã§ããä»ã«ã宣èšã³ãã³ãã§ã¯æ¬¡ã®ããã«é åãæ±ã£ããããããšãã§ããŸããéåžžã®ã³ãã³ãã§ã¯ãã®ãããªåŒæ°ã®æžãæ¹ããããšææ³ãšã©ãŒã«ãªããã宣èšã³ãã³ããšããåºå¥ãå¿ èŠãªã®ã§ãã
foo() {
local ary=(1 2 3)
}
宣èšã³ãã³ã㯠POSIX ã·ã§ã«ã®å
ã«ãªã£ã ksh88 ã®æç¹ã§ãã§ã«ååšããŠããæŠå¿µã§ãããèŠéãããŠããã®ã POSIX ã§æšæºåãããŠããŸããã§ãããã¡ãªã¿ã« Bourne ã·ã§ã«ã«ã¯å€æ°ãžã®ä»£å
¥ã®åœ¢ãããã³ãã³ãã¯ãããŸãããexport
ã³ãã³ãã readonly
ã³ãã³ãã¯å€æ°ã®å±æ§ãå€ããããšããã§ãããåæã«ä»£å
¥ããããšã¯ã§ããŸããã§ãããã€ãŸã宣èšã³ãã³ã㯠ksh88 ã§æ°ããè¿œå ãããæ©èœãšããããšã§ããbashãmkshãkshãzshãFreeBSD shãOpenBSD shã§ã ksh88 ãšåæ§ã®åäœãè¡ããŸããããã¹ãŠã®ã·ã§ã«ã宣èšã³ãã³ãã«ãªã£ãŠããããã§ã¯ãªããdash 0.5.10 ãšãã以åãNetBSD shïŒNetBSD 10.0æç¹ïŒãyashïŒ2.56æç¹ïŒã§ã¯å®£èšã³ãã³ãã§ã¯ãªãæåãããŸãããã®ããçŸæç¹ã§ã¯ export
ãªã©ã§ä»£å
¥å€ãšããŠå€æ°ã䜿ãå Žåã¯ããã«ã¯ã©ãŒãããŠãããã»ããå®å
šã§ãããã¡ããéåžžã®å€æ°ä»£å
¥ã§ããã°ããã«ã¯ã©ãŒãã¯ãªããŠãæ§ããŸããã
# çŸæç¹ã§ã¯å®£èšã³ãã³ãã§ãããã«ã¯ã©ãŒãããŠãããæ¹ãå®å
š
export VAR1="$var"
# éåžžã®å€æ°ä»£å
¥ãªãããã«ã¯ã©ãŒãã¯ãªããŠãè¯ã
VAR1=$var
å åšã³ãã³ã (Intrinsic Utilities)
ãå åšã³ãã³ãã㯠Intrinsic Utilities ã«å¯ŸããŠç§ãä»ããèš³ã§ããIntrinsic ã¯ïŒã·ã§ã«ã«ïŒãæ¬æ¥åãã£ãŠããããšããæå³ãããã§ã¯äžçªç確ã ãšæããŸããããæ¬è³ªïŒçïŒã³ãã³ãããšããåºæã³ãã³ããã§ã¯ãã£ããããªãã®ã§ïŒèªåã§ãããŸãæºè¶³ããŠããªãã®ã§ããïŒå åšã³ãã³ããšèš³ããŠããŸããå éšã³ãã³ããšãèš³ãããšæããŸãããããã ãšã·ã§ã«ãã«ãã€ã³ã³ãã³ããšæ··åããŠããŸãã®ã§ã
å åšã³ãã³ãã®èª¬æã®åã«ãŸãåæç¥èãšããŠã·ã§ã«ãã«ãã€ã³ã³ãã³ãã®è©±ã§ããã·ã§ã«ã«çµã¿èŸŒãŸããã³ãã³ããã·ã§ã«ãã«ãã€ã³ã³ãã³ããšåŒã³ãŸããã倧ããåããŠãç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãããšãéåžžã®ã·ã§ã«ãã«ãã€ã³ã³ãã³ããã®ïŒã€ã«åé¡ããããšãã§ããŸããç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãã¯ã·ã§ã«ã®æ©èœãšæ·±ãçµã³ã€ããŠãã以äžã®ã³ãã³ãã§ãã
. : break continue eval exec exit export
readonly return set shift times trap unset
ç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ã㯠if
ã for
ãšãã£ãã·ã§ã«ã®ããŒã¯ãŒãïŒäºçŽèªïŒã«è¿ããã®ã§ãããç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãã¯ãã³ãã³ãã®ææ³ããã€ãŸãã³ãã³ãåãšåŒæ°ãæå³ããåèªã®äžŠã³ãšããåçŽãªåœ¢ãããŠãããã®ã§ããããã«å¯ŸããŠããŒã¯ãŒãã¯åçŽãªåèªã®äžŠã³ã§ã¯ãªãç¹æ®ãªè§£éïŒfi
ã§çµãã£ãã in
ã䜿ã£ããïŒãè¡ããŸãããŸãç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãã¯ïŒPOSIX ã§ã®å®çŸ©ã§ã¯ïŒååã®ã·ã§ã«é¢æ°ã§åå®çŸ©ã§ããªããšããç¹åŸŽãæã£ãŠããŸããå®éã«ã¯ã·ã§ã«ã«ãã£ãŠã¯ç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãã§ãã·ã§ã«é¢æ°ã§åå®çŸ©ã§ããŠããŸãã®ã§ãããbash ã§ã¯ POSIX æºæ ã¢ãŒãã«ãããšåå®çŸ©ã§ããªããªããŸãã
ãããŸã§ã¯ç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ã以å€ã®ã³ãã³ãã¯ãã¹ãŠãéåžžã®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãããšããã®ã POSIX ã§ã®æšæºåãããå®çŸ©ã§ãããéåžžã®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãã®ã³ãã³ãå㯠POSIX ã§ã¯èŠå®ãããŠããŸãããããã¯éåžžã®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãã¯ãããã©ãŒãã³ã¹ãªã©ãçç±ã«ã·ã§ã«éçºè ã®å€æã§çµã¿èŸŒãã§ãããã®ã§ãæ¬è³ªçã«ã¯å€éšã³ãã³ããšåããã®ãšããæ±ãã ããã§ããäœãã·ã§ã«ã«çµã¿èŸŒããã¯ã·ã§ã«éçºè ã®èªç±ã§ãã
POSIX ã«ãšã£ãŠéåžžã®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãã¯ã·ã§ã«ã«çµã¿èŸŒãŸããŠãããšããç¹ãé€ããŠå€éšã³ãã³ããšã®éãã¯ãããŸãããããã¯ãã·ã§ã«ãã«ãã€ã³ã³ãã³ãã¯å€éšã³ãã³ããšåãããã«ç°å¢å€æ° PATH
ã䜿ã£ãã³ãã³ãã®æ€çŽ¢åŠçãè¡ããããããšãæå³ããŠããŸããã€ãŸãå€ãã®äººãèããŠããã§ããããã·ã§ã«ãã«ãã€ã³ã³ãã³ããšå€éšã³ãã³ãã§åãååã®ã³ãã³ããããå Žåãã·ã§ã«ãã«ãã€ã³ã³ãã³ãã®æ¹ãåªå
ãããã㯠POSIX ã®å®çŸ©çã«ã¯éããšããããšã§ãããã£ãšããããããèšãã°ãç°å¢å€æ° PATH
ã䜿ã£ãŠã·ã§ã«ãã«ãã€ã³ã³ãã³ããããå€éšã³ãã³ããåªå
ãããããšãã§ããŸãããã®æ¹æ³ã«ã€ããŠã¯ãã€ããŒããã話ã§ãå€åå¥ã®èšäºãæžããšæãã®ã§ããã§ã¯çç¥ããŸãããèå³ãããæ¹ã¯ POSIX.1-2024 ãèªãã§ã¿ãŠãã ããããããã POSIX.1-2024 ãèªãã§ãããããªããšæããŸããã·ã§ã«äŸåã®åäœã§å
·äœçãªããšãæžãããŠããªãããã§ãã
ããŠç°å¢å€æ° PATH
ã䜿ã£ãŠãéåžžã®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãããããå€éšã³ãã³ãã®æ¹ãåªå
ãããããšãã§ãããšããäœã§è©±ãé²ããŸãããçŸå®ã®ã·ã§ã«ã®å®è£
ã¯äžéšã®ã³ãã³ãã«å¯ŸããŠã¯å€éšã³ãã³ããåªå
ãããããšãã§ããŸããã§ãããç°å¢å€æ° PATH
ã䜿ã£ãã³ãã³ãæ€çŽ¢ãè¡ããªãã³ãã³ãããããã·ã§ã«ã«æ¬æ¥åãã£ãŠãããå
åšã³ãã³ããã§ããå
åšã³ãã³ããšããŠå®çŸ©ãããã³ãã³ãã«ã¯æ¬¡ã®ãããªãã®ããããŸãã
alias bg cd command fc fg getopts hash
jobs kill read type ulimit umask unalias wait
ãããã¯ããããã·ã§ã«ã®ããã»ã¹èªäœã«åœ±é¿ãäžãããã·ã§ã«ã®ããã»ã¹ã®æ å ±ãå¿ èŠãšãããã®ã§ããå€éšã³ãã³ãã§å®è£ ããã®ãïŒäžå¯èœã§ã¯ãªããã®ã®ïŒé£ãããããçŸå®ã®ã·ã§ã«ã®å®è£ ã¯å€éšã³ãã³ããåªå ãããæ¹æ³ãçšæããŠããŸãããå人çã«ã¯ããããç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ããšããŠã«ããŽãªããéããã£ãã®ã§ã¯ãªãããšèããŸãããç¹æ®ã·ã§ã«ãã«ãã€ã³ã³ãã³ãã¯å åšã³ãã³ããšã¯å¥ã®ç¹åŸŽãæã£ãŠãããå¥ã®ã«ããŽãªãäœã£ãã»ããè¯ãïŒæšæºåã®æéãå°ãªãïŒãšèããã®ã§ãããã
ã·ã§ã«ã®å®è£
ã«ãã£ãŠã¯ POSIX ã§å®çŸ©ãããã³ãã³ã以å€ã®å
åšã³ãã³ããæã£ãŠããããšããããŸãããPOSIX ã§ã¯ååãšããŠããã以å€ãå
åšã³ãã³ããšããŠå®è£
ããªãããã«æšå¥šããŠããŸããã©ããã£ãŠã POSIX ã¯éåžžã®ã·ã§ã«ãã«ãã€ã³ã³ãã³ããšå€éšã³ãã³ããåºå¥ããããªãããã§ãããŠãŒã¶ãŒãç°å¢å€æ° PATH
ãå€æŽããŠäŸåããå€éšã³ãã³ãã®å®è£
ãå€æŽããããšãããšããã·ã§ã«ãã«ãã€ã³ã³ãã³ããåŒã³åºãããããšã«ãã£ãŠå€éšã³ãã³ãã®åŒã³åºããäžå¯èœã«ãªãã®ã§ããã°ãç°ãªãã·ã§ã«ã®éã§ã·ã§ã«ã¹ã¯ãªããã«ç§»æ€æ§ãããããããšãã§ããªããšããèãããã®ããã§ããããããªããç¹å®ã®ã·ã§ã«ã§åãããšæ±ºããã·ã§ã«ã¹ã¯ãªããã§ã¯ã·ã§ã«ã«ã³ãã³ããå
èµãããŠããã»ããç°å¢äŸåããªããªããšããç®èãªçŸå®ããããŸãã
echo ã³ãã³ã
echo
ã³ãã³ãã¯æååãåºåããããªãã¿ã®ã³ãã³ãã§ããå¿
ãããã·ã§ã«ã«çµã¿èŸŒãå¿
èŠã¯ãããŸããããïŒããã«ããã©ãŒãã³ã¹äžã®çç±ã§ïŒãã¹ãŠã® POSIX ã·ã§ã«ã«çµã¿èŸŒãŸããŠãããããã§ã¯ã·ã§ã«ã®æ©èœãšããŠæ±ããŸãããã ãã·ã§ã«ã«ãã£ãŠåäœãç°ãªã移æ€æ§ãäœãã³ãã³ãã§ããããŸãã
ãšã¹ã±ãŒãã·ãŒã±ã³ã¹ã®è§£éãå¶åŸ¡ãã-eã-Eãæªæå®ãšããŠæšæºå
ä»ãŸã§ echo
ã³ãã³ãã® -e
ãªãã·ã§ã³ã -E
ãªãã·ã§ã³ã¯ POSIX ã§èšåãããŠããŸããã§ãããã€ãŸãæååãšããŠåºåããå¿
èŠããããå€ãã®ã·ã§ã«ã¯ POSIX ã«æºæ ããŠããªãç¶æ
ã§ãããPOSIX.1-2024 㧠-e
ã-E
㯠-n
ãšåãããæªæå®ãšããŠæšæºåããããŸãããããã¯ã·ã§ã«ã®å®è£
ãã©ã®ãããªåäœã§ãè¯ãïŒPOSIX ã«éåããªãïŒããšãæå³ããŠããŸãã-e
ã-E
ã-n
ãã©ã®ãããªåäœãè¡ããªãã·ã§ã³ã§ããã㯠POSIX ã§èŠå®ãããŠããªãããšã«æ³šæããŠãã ããããããã®åäœã¯æ¡åŒµæ©èœãšããŠåã·ã§ã«ãèªç±ã«åäœã決ããããšãã§ããŸãããŸã echo
ã³ãã³ãã®åŒæ°ã«ããã¯ã¹ã©ãã·ã¥ãå«ãŸããå Žåããã®åäœã¯ïŒä»ãŸã§éãïŒæªæå®ã§ããã·ã§ã«ã«ãã£ãŠããã©ã«ãã§ãšã¹ã±ãŒãã·ãŒã±ã³ã¹ã解éããã解éããªãã£ããããã®ã§æ³šæããŠãã ããã
åé¿ç: 移æ€æ§ã®ããechoã³ãã³ãçžåœã®å®è£
移æ€æ§ãéèŠãªå Žå echo
ã³ãã³ãã䜿ãã®ã¯æšå¥šã§ããŸããã代ããã« printf
ã³ãã³ãã䜿ããããšããã§ãããmksh ã§ã¯ printf
ã³ãã³ããå€éšã³ãã³ããªã®ã§é
ããªããŸãã次ã®ãããªã·ã§ã«é¢æ°ãå®çŸ©ããããšã§ã移æ€æ§ã®åé¡ã解決ãã€ã€ããã©ãŒãã³ã¹äœäžãé¿ããããšãã§ããŸãã
if [ "${KSH_VERSION:-}" ]; then
put() {
IFS=" $IFS" && set -- "${*:-}" && IFS=${IFS# }
print -nr -- "$1"
}
putln() {
IFS=" $IFS" && set -- "${*:-}" && IFS=${IFS# }
print -r -- "$1"
}
else
put() {
IFS=" $IFS" && set -- "${*:-}" && IFS=${IFS# }
printf '%s' "$1"
}
putln() {
IFS=" $IFS" && set -- "${*:-}" && IFS=${IFS# }
printf '%s\n' "$1"
}
fi
put foo bar baz # echo -n ãšåç
putln foo bar baz # echo ãšåç
cd ã³ãã³ã
cd
ã³ãã³ãã¯ãã£ã¬ã¯ããªã移åããã³ãã³ãã§ãã
åŒæ°ã®ãã£ã¬ã¯ããªåã«ç©ºæåãæå®ããå Žåã«ãšã©ãŒã«ãªã
cd
ã³ãã³ãã®åŒæ°ã®ãã£ã¬ã¯ããªåã«ç©ºæåãæå®ãããšãã«ãšã©ãŒã«ãªãããã«èŠå®ãããŸããããããŸã§ã¯ç©ºæåãæå®ãããšãã®åäœã¯æªæå®ã§ãããã€ãŸãçŸå®ã®ã·ã§ã«ã§ã¯ã·ã§ã«ã«ãã£ãŠåäœãç°ãªã£ãŠãããšããããšãæå³ããŸãã
$ cd ""
ksh: cd: bad directory
äžéšã®ã·ã§ã«ã§ã¯ cd
ã³ãã³ãã®åŒæ°ã®ãã£ã¬ã¯ããªåã空æåã®å Žåãã«ã¬ã³ããã£ã¬ã¯ããªãžã®ç§»åãæå³ããŸããããã ls
ã³ãã³ããªã©ã§ã¯ãã£ã¬ã¯ããªåã空æåã®å Žåãã«ã¬ã³ããã£ã¬ã¯ããªãæå³ããŸããã空æåããšã©ãŒã«ãããšããä»æ§ã®å€æŽã¯ãå®å
šæ§ã®ç¹ããã¯åŠ¥åœãªãã®ã§ãããšèããããŸãããåé¡ã¯çŸåšããã€ãã®ã·ã§ã«ã¯ãšã©ãŒã«ãªããªããšããç¹ã§ããã€ãŸã POSIX ãèªãã§ç©ºæåãæå®ããå Žåã«ãšã©ãŒã«ãªããšæã蟌ãã§ãããšãå®éã®ã·ã§ã«ã§ã¯ããã§ã¯ãªããããã°ã®åå ãšãªã£ãŠããŸããŸããçŸå®ã«äœ¿ãããŠãããã¹ãŠã®ã·ã§ã«ã空æåãæå®ããå Žåã«ãšã©ãŒã«ãªãã®ã«ã¯æéããããã§ãããã
ãªãã空æåãæå®ããŠããšã©ãŒã«ãªããªããã€ãŸãçŸæç¹ã§ POSIX.1-2024 ã«æºæ ããŠããªãã·ã§ã«ã«ã¯ãdashãbashãmkshãyashãzshãBusybox ashãFreeBSD shãNetBSD shãOpenBSD shãksh88 ãšã»ãšãã©ã§ããéã«ãšã©ãŒã«ããã·ã§ã«ã¯ ksh93ïŒæ¯èŒçæ°ããããŒãžã§ã³ïŒãksh93u+mãBourne ã·ã§ã«ãšããããããããŸãããçŸå®ã®å®è£ ã®ææåãšã¯èšããªãããããã®å€æŽã¯å¿ èŠã ã£ãã®ãçåãæ®ããŸãããŸãä»æ§ãå€æŽããåã«å ¬éãããã¯ãã®ãå°æ¥ã®æ¹åæ§ãšããŠç©ºæåããšã©ãŒã«ãããšããèšè¿°ãèŠåœãããªãã®ã§ãæšæºåããã»ã¹ã«äœãããã®ãã¹ããã£ãã®ã§ã¯ãªãããšæããŠããŸãïŒæ¬æ¥å ¬éãããã¯ãã® TC3 ãæ€åãããïŒïŒã
2024-06-30 è¿œèš bash (5.3?) 㧠POSIX.1-2024 æºæ ã«ä¿®æ£ãããããã§ã
çŸåšã®ãã£ã¬ã¯ããªåãäžæãªå Žåã«ãšã©ãŒã«ãã-eãªãã·ã§ã³
cd
ã³ãã³ãã® -e
ãªãã·ã§ã³ã¯ã-P
ãªãã·ã§ã³ãæå®ãããšãã®ã¿æå®ã§ãããªãã·ã§ã³ã§ãã-P
ãªãã·ã§ã³ã¯ç©ççãªãã£ã¬ã¯ã㪠(physical directory) ã«ç§»åããããã®ãªãã·ã§ã³ã§ããããã£ã¬ã¯ããªã®ç§»åãæ£ããè¡ãããã®ã«çŸåšã®ãã£ã¬ã¯ããªåãååŸã§ããªãç¶æ³ããããŸããäŸãã°å¯Ÿè©±ã·ã§ã«ã§ã«ã¬ã³ããã£ã¬ã¯ããªãåé€ããå Žåã§ãããã®å Žåãã£ã¬ã¯ããªã¯åé€ãããŸããããã®ãã£ã¬ã¯ããªãåç
§ããŠããã·ã§ã«ã¯ãã£ã¬ã¯ããªãåç
§ããŠããéãã¢ã¯ã»ã¹å¯èœã§ããããã¯ãªãŒãã³ããŠãããã¡ã€ã«ãåé€ããŠãããã¡ã€ã«ããªãŒãã³ããŠããéãåç
§ã§ããã®ãšåãçå±ã§ãããã¹ã¯æ¶ããŸããæ¬åœã«ãã¡ã€ã«ãåé€ãããã®ã¯ãã¡ã€ã«ãã¯ããŒãºãã段éã§ãããã®ãããªå Žåã«ãã£ã¬ã¯ããªã¯ç§»åã§ããã®ã«ãã£ã¬ã¯ããªåãååŸã§ããªãç¶æ³ã«ãªããŸãã
çŸåšã®ãã£ã¬ã¯ããªå㯠PWD
ã·ã§ã«å€æ°ããååŸããããšãã§ããŸãããã·ã§ã«ã¹ã¯ãªããã«ãšã£ãŠå¿
ãããå¿
èŠãªæ
å ±ã§ã¯ãããŸãããæ£ãã移åã§ããŠããã°ããã§ååãªå ŽåããããŸããããããã¡ãããã£ã¬ã¯ããªåãå¿
èŠãªå ŽåããããŸãã-e
ãªãã·ã§ã³ãæå®ããªãå Žåãcd
ã³ãã³ãã¯æå®ãããã£ã¬ã¯ããªã«æ£ãã移åã§ãããã©ããã®ã¿ãèæ
®ããŠçµäºã¹ããŒã¿ã¹ã決å®ããŸãã-e
ãªãã·ã§ã³ãæå®ããå Žåã¯ããã«çŸåšã®ãã£ã¬ã¯ããªåãååŸå¯èœïŒPWD
ã·ã§ã«å€æ°ã«æ£ãã代å
¥ã§ãããïŒãŸã§èæ
®ããŠçµäºã¹ããŒã¿ã¹ã決å®ããŸãã
printf ã³ãã³ã
printf
ã³ãã³ã㯠echo
ã³ãã³ãã®ç§»æ€æ§åé¡ã解決ããããã«äœãããæååãåºåããããã®ã³ãã³ãã§ããå¿
ãããã·ã§ã«ã«çµã¿èŸŒãå¿
èŠã¯ãªããå®éã« mksh ã§ã¯çµã¿èŸŒãŸããŠããŸãããã倧åã®ã·ã§ã«ã«çµã¿èŸŒãŸããŠããããããã§ã¯ã·ã§ã«ã®æ©èœãšããŠæ±ããŸãã
åŒæ°äœçœ®ãæå®ããåç §
printf
ã³ãã³ã㧠%s
ã®ä»£ããã« %2$s
ã®ãããªæå®ïŒn$
ïŒã§åç
§ããåŒæ°ã®äœçœ®ãæå®ã§ããããã«ãªããŸããããã®æ©èœã¯ ksh93 ãš zsh ã§ä»¥åããå®è£
ãããŠããŸãããbash 5.2 æç¹ã§ã¯å®è£
ãããŠããŸããã
$ printf 'ããã«ã¡ã¯, %2$s %1$s\n' Koichi Nakashima
ããã«ã¡ã¯, Nakashima Koichi
äžèšã®äŸãèŠãŠãããããã«ããã®æ©èœã¯ã·ã§ã«ã¹ã¯ãªããã®åœéå察å¿ã«å¿ èŠãªæ©èœïŒèšèªã«ãã£ãŠåèªã®é çªãç°ãªãããïŒãšããŠæšæºåãããŸããã
POSIX ã®å°æ¥ã®ããŒãžã§ã³ã§ã¯ãæå®ããäœçœ®ã®åŒæ°ãååšããªãå Žåã¯ãšã©ãŒãšããããšãèŠæ±ãããããããªãããšãèšèŒãããŠããŸãã
å°æ¥ã®æ¹åæ§: %b ãš %q ã®è¿œå
å°æ¥ã®æ¹åæ§ãšã㊠printf
ã³ãã³ãã« %b
ãš %q
æžåŒã®è¿œå ãèšèŒãããŸãããå°æ¥ã®æ¹åæ§ã¯å¿
ãããå®çŸãããšã¯éããŸãããPOSIX ãïŒèª°ãããã®ææ¡ã«ããïŒã·ã§ã«ã«å®è£
ããŠæ¬²ãããšèããŠããææ¡ã®ãããªãã®ã§ãå®çŸãããã©ããã¯ã·ã§ã«å®è£
è
ãå®è£
ãããªã©ããŠæšæºåããã«å€ãããš POSIX ãèããå Žåã§ãã
%b
ã¯æ°å€ã2é²æ°ã«å€æããŠåºåããæžåŒã§ããçŸåšã®å®è£
ã§ã¯ %b
ã¯ãšã¹ã±ãŒãã·ãŒã±ã³ã¹ã解éããæžåŒãšããŠå¥ã®æå³ã§äœ¿çšãããŠãããããæ°ããæžåŒã䜿çšããããã® -C
ãªãã·ã§ã³ã®ãããªãã®ããããšè¯ããš POSIX ã¯ææ¡ããŠããŸããçŸåšã®å®è£
ã« -C
ãªãã·ã§ã³ãå®è£
ããŠããã·ã§ã«ã¯ãªãããããã«æšæºåã¯ã§ããŸããã%b
ã®è¿œå 㯠ISO C æšæºã®æ¬¡ã®ããŒãžã§ã³ã® printf
é¢æ°ã®ä»æ§ã«å¯Ÿå¿ããŠã®ãã®ã§ãCèšèªã® printf
é¢æ°ãšæåãç°ãªããšæ··ä¹±ãããšããã®ãææ¡ã®åæ©ã®ããã§ãã
%q
ã¯æååãã·ã§ã«ã®å
¥åãšããŠæ±ããããã«ãšã¹ã±ãŒãããããã®æžåŒã§ããææ¡ã®ææãé
ããŸãäžèšã®åé¡ïŒ-C
ãªãã·ã§ã³ã®è¿œå ãè¡ããããã©ããïŒã«é¢é£ããŠããããæšæºåã«è³ããŸããã§ãããããã§ã« bashãkshãmkshãzsh ã§å®è£
ãããŠããããæšæºåãããå¯èœæ§ã¯é«ãã§ãããã
read ã³ãã³ã
read
ã³ãã³ãã¯ããŒã¿ãå
¥åããããã®ã³ãã³ãã§ãã
æ¹è¡ã®ä»£ããã«ãã«æåãªã©ãçµç«¯æåãšããŠäœ¿ã-dãªãã·ã§ã³ã®è¿œå
find
ã³ãã³ãã® -print0
ã§åºåããããã«æåçµç«¯ããŒã¿ãèªã¿èŸŒãã«ã¯ãäŸãã° xargs
ã³ãã³ãã« -0
ãªãã·ã§ã³ãæå®ããå¿
èŠããããŸããããããšåãããã« read
ã³ãã³ãã® -d
ãªãã·ã§ã³ã§ç©ºæåãæå®ãããšããã«æåçµç«¯ããŒã¿ãèªã¿èŸŒãããšãã§ããããã«ãªããŸããã
$ find . -print0 | while IFS= read -d '' line; do echo "$line"; done
ãã«æå以å€ã®æåãæ±ãããšãã§ããŸãã
$ echo foo:bar:baz: | while IFS= read -d : line; do echo "$line"; done
foo
bar
baz
ãã®æ©èœã¯ä»¥åããbashãmkshãksh93ãzshã§äœ¿çšå¯èœã§ããããã ã ksh93 ã§ã¯ãã°ã§ãã«æåãæå®ããããšãã§ããŸããããã®ãã°ã¯ ksh93u+m ã§ä¿®æ£ãããŠããŸãã
set ã³ãã³ã
set
ã³ãã³ãã¯ã·ã§ã«ãªãã·ã§ã³ã®èšå®ãäœçœ®ãã©ã¡ãŒã¿ã®èšå®ãè¡ãããã®ã³ãã³ãã§ãã
# ã·ã§ã«ãªãã·ã§ã³ã®èšå®
set -o errexit
# äœçœ®ãã©ã¡ãŒã¿ã®èšå®
set -- a b c
echo "$1, $2, $3" # => a, b, c
ãã€ãã©ã€ã³ã®éäžã®ãšã©ãŒãååŸãã-o pipefailã®è¿œå
set -o pipefail
ãå®è¡ããŠããªãå Žåããã€ãã©ã€ã³å
šäœã®çµäºã¹ããŒã¿ã¹ã¯ãæåŸã®ã³ãã³ããã®ãã®ãšãªããŸãããã®åäœãå€æŽããæåŸã«ãšã©ãŒã«ãªã£ãã³ãã³ããã®çµäºã¹ããŒã¿ã¹ã«ããã®ã set -o pipefail
ã§ããã¡ãªã¿ã« -o
ãªãã·ã§ã³ã«ããé·ãååã§ã®æå®æ¹æ³ã¯ Bourne ã·ã§ã«ã§ã¯äœ¿ããŸããã§ããããPOSIX ã·ã§ã«ã§ã¯ä»¥åããæšæºåãããŠããŸãã
$ echo "abc" | grep "d" | tr a-z A-Z
$ echo $?
0
$ (set -o pipefail; echo "abc" | grep "d" | tr a-z A-Z)
$ echo $?
1
ãã®æ©èœã«ã€ããŠã¯å€ãã®ã·ã§ã«ã§å®è£ æžã¿ã§ãããbashãksh93ãzshã«é¢ããŠã¯ããªãæããããã®ä»ã®ã·ã§ã«ã§ã¯ FreeBSD sh ã¯2019幎6æã® FreeBSD 11.3 ããïŒFreeBSD 11.x ã¯ãã§ã«ãµããŒãçµäºïŒãNetBSD sh ã OpenBSD sh ããã§ã«ãµããŒãããŠããŸããäžçªã®çŸå®çãªæžå¿µç¹ã¯ dash ã§ãã 2024-04-05 ã«å¯Ÿå¿ãå®äºãããŠããããããã次㮠v0.5.13 ã§å¯Ÿå¿ããã§ãããã
ã·ã§ã«ã¹ã¯ãªããã§ã®ïŒpipefailãæå¹ã«ããïŒãã€ãã©ã€ã³ã®ãšã©ãŒåŠçã®äžè¬çãªæžãæ¹ã¯ãã®ããã«ãªããŸãã
#!/bin/sh
set -o pipefail
if echo "abc" | grep "d" | tr a-z A-Z; then
echo æ£åžžçµäº
else
echo ãšã©ãŒçµäº
fi
泚æç¹ãšããŠã移æ€æ§ãå¿
èŠãªå Žå PIPESTATUS
é
åã¯äœ¿çšããªãããã«ããŠãã ãããPIPESTATUS
é
å㯠bash ãš mkshïŒR40以éïŒã§ãã䜿ããªãæ©èœã§ãããã€ãã©ã€ã³å
šäœã®ã©ããã§ãšã©ãŒãèµ·ãããã調ã¹ããã ããªã PIPESTATUS
é
åã調ã¹ãå¿
èŠã¯ãããŸããã
åé¿ç: sh-pipestatus - PIPESTATUSãšpipefailã®ä»£æ¿å®è£
ãã pipefail ã«ãŸã 察å¿ããŠããªãã·ã§ã«ã§ pipefail ã®æ©èœã䜿çšãããå Žåã¯ãsh-pipestatus ãšããã©ã€ãã©ãªãäœã£ãŠããã®ã§ããã䜿çšããŠãã ããã次ã®ãããªæãã§ç°¡åã« pipefail æ©èœãšåçã®ããšãè¡ãããšãã§ããŸãã
#!/bin/sh
. ./pipestatus.sh
if pipe -fail 'echo "abc" | grep "d" | tr a-z A-Z' "$@"; then
echo æ£åžžçµäº
else
echo ãšã©ãŒçµäº
fi
ã¡ãªã¿ã« sh-pipestatus ã®æ¬æ¥ã®æ©èœã¯ãååã®éã bash ã® PIPESTATUS
é
åæ©èœããšãã¥ã¬ãŒãããããã®ã©ã€ãã©ãªã§ããPIPESTATUS
é
åã®ä»£ããã« PIPESTS
å€æ°ã«ãã€ãã©ã€ã³ã®åã³ãã³ãã®çµäºã¹ããŒã¿ã¹ãã¹ããŒã¹åºåãã§ä»£å
¥ããŸããPIPESTATUS
é
å㯠POSIX ã§æšæºåãããŠããªãã®ã§ãããå¿
èŠãªå Žåã¯ãã®ã©ã€ãã©ãªã䜿ãããšãã§ããŸãã
ããŸãã§ããã€ãã䜿çšããæã«åé¡ã«ãªã SIGPIPE
ã«ãããšã©ãŒãç¡èŠããããã® igpipe
ã·ã§ã«é¢æ°ãå®è£
ããŠããŸãã
set -o pipefail
seq 100000 | cat | head >/dev/null
echo $? # => 141
igpipe seq 100000 | igpipe cat | head >/dev/null
echo $? # => 0
test / [ ... ] ã³ãã³ã
testïŒ[ ... ]
ïŒã³ãã³ãã«ããã€ãã®æŒç®åãè¿œå ãããŸããããã®è°è«ã®äžã§ ksh93 ã§å®è£
ãã bash ã zsh ãªã©ã«ãåºãŸã£ã [[ ... ]]
ãæšæºåããããšããæèŠãã§ãŸãããã[ ... ]
ãš [[ ... ]]
ã«ã¯ã»ãšãã©éãããªããæšæºåããŠã移æ€æ§ã¯é«ãŸããšã¯èšãããçŸåšã®ã·ã§ã«ã®å®è£
ã®éã«éããããããããšããŠåŽäžãããããã§ããããããã [ ... ]
ã«è¶³ããªãæŒç®åãè¿œå ããæ¹ãè¯ããšããçµè«ã«ããè¡ãããŸãããã¡ãªã¿ã« =
ã®å¥åãšããŠã® ==
ã®è¿œå ã¯ã¡ãªããããªããªã©ã®çç±ã§åæã«è³ããå«ãŸããŸããã§ããããã㊠[[ ...]]
ã«ã¯ãã£ãã [ ... ]
ã«ã¯ãªãã£ãè¿œå ã®æŒç®åã [ ... ]
ã«å¯ŸããŠãåºãå®è£
ãããããæšæºåãããããšã«ãªããŸããã
æååã®å€§å°ãæ¯èŒããããã® <, > æŒç®åã®è¿œå
æååã®å€§å°ãæ¯èŒããããã® <
>
æŒç®åãè¿œå ãããŸãããã·ã§ã«ã®ææ³ã§ãã [[ ... ]]
ãšã¯éã£ãŠ [ ... ]
ã¯ã³ãã³ããªã®ã§ <
>
æŒç®åã¯ãšã¹ã±ãŒãããå¿
èŠãããããšã«æ³šæããŠãã ããããšã¹ã±ãŒãããªããã°ãªãã€ã¬ã¯ãæåãšããŠè§£éãããŠããŸããŸãã
$ [ a \< b ] && echo ok
ok
$ [ a '<' b ] && echo ok
ok
ãã¡ã€ã«ãæ¯èŒããããã® -ef, -nt, -ot æŒç®åã®è¿œå
ãã¡ã€ã«ãåããã©ãããæ¯èŒãã -ef
ãšæŽæ°æ¥æãæ¯èŒããããã® -nt
ã -ot
æŒç®åãè¿œå ãããŸããã
-ef
(equal files) ã»ã»ã» ãã¡ã€ã«ãåäžïŒiããŒããåãïŒã§ããã°ç
-nt
(newer than) ã»ã»ã» å·Šã®ãã¡ã€ã«ãå³ãããæ°ãããã°ç
-ot
(older than) ã»ã»ã» å·Šã®ãã¡ã€ã«ãå³ãããå€ããã°ç
-a (AND) / -o (OR) æŒç®åã®åé€
以åããéæšå¥šãšãªã£ãŠãã -a
(AND) ãš -o
(OR) æŒç®åã POSIX ããåé€ãããŸãããPOSIX ããåé€ããããšããããšã®æå³ã¯ãå®éã®ã·ã§ã«ããåé€ããããšãèŠè«ããŠããã®ã§ã¯ãªãã移æ€æ§ããªãæ©èœãªã®ã§ïŒç§»æ€æ§ãããã·ã§ã«ã¹ã¯ãªãããæžããã人ã¯ïŒäœ¿çšããªãããã«æšå¥šããŠãããšããããšã§ããå®éã®ã·ã§ã«ã¯äºææ§ãä¿ã€å¿
èŠããããããäžè¬çã«ã¯ POSIX ããåé€ããããããšèšã£ãŠã·ã§ã«ãæã€æ©èœããåé€ããããšã¯ãŸããããŸããããã€ããŒãªã·ã§ã«ãåé€ãããèšå®ã«ããèŠåãåºãããã«ããããšã¯ãããããããŸãããã
åé€ãããçç±ã«ã€ããŠã¯ãOils (Oils for Unix) ãããžã§ã¯ãã®äžèšã®èšäºãåèã«ãªããŸãã
What Does [ -a -a -a -a ] Mean?
詳现ã¯äžèšã®ãµã€ãã«æžããŠãããŸããã[ -a -a -a -a ]
ã«ã¯ããã€ãã®è§£éããããŸããããã¯æŽå²çãªã·ã§ã«ïŒksh88ãªã©ïŒã -a
ããåŒ1 -a åŒ2
: ANDããšã-a ãã¡ã€ã«å
: ãã¡ã€ã«ãååšããŠããïŒããšããæèã«ãã£ãŠç°ãªã2ã€ã®æå³ãæã£ãŠããã£ãããã§ããã¡ãªã¿ã« -o
ã«ããåŒ1 -o åŒ2
: ORããšã-o ãªãã·ã§ã³å
: ã·ã§ã«ãªãã·ã§ã³ãæå¹ãïŒãã®2ã€ã®æå³ããããŸããPOSIX ã§ã¯ -a ãã¡ã€ã«å
ãš -o ãªãã·ã§ã³å
ã®çšæ³ã¯æšæºåãããŠããŸãããPOSIX ã§æšæºåãããŠããªããšèšã£ãŠããå®éã®ã·ã§ã«ã¯å¯Ÿå¿ããŠããããã§åºã䜿ãããŠãã AND ãš OR ã®çšæ³ã¯éæšå¥šã§ãããªãããæšæºåãããŠããŸãããããã®ãã³ãã§ãã POSIX ããåé€ããããšããæµãã§ããAND ãš OR ããªããªã£ããšããããšã¯ ( ... )
ã䜿ãæå³ããããŸããã®ã§ããã¡ããåé€ãããŠããŸããçµè«ãšããŠã¯ç§»æ€æ§ãããã·ã§ã«ã¹ã¯ãªãããæžãããã®ã§ããã° -a
ãš -o
ã¯äœ¿ãããã·ã§ã«ã®æ©èœã§ãã &&
ãš ||
ã䜿ããŸããããšããããšã§ãã
è£è¶³ã§ãããäžèšãµã€ãã® Oils (Oils for Unix) ãããžã§ã¯ãïŒä»¥åã®åå㯠Oil shell ãããžã§ã¯ãïŒã¯ãbash äºæã®ã·ã§ã«ã®å®è£ ã§ãã OSH ã®éçºãšã¬ã¬ã·ãŒããªãŒãªããè¯ãã·ã§ã«ã®å®è£ ã§ãã YSH ïŒä»¥åã®åå㯠Oil èšèªïŒãéçºããŠãããµã€ãã§ãã
trap ã³ãã³ã
trap
ã³ãã³ãã¯ã·ã°ãã«ãã³ãã©ã®èšå®ãã€ãŸãä»»æã®ã·ã°ãã«ãåãåã£ããšãã«ãæå®ããã³ãã³ãïŒã·ã§ã«é¢æ°ãå«ãïŒãå®è¡ããããã«èšå®ããã³ãã³ãã§ãã
# ã·ã°ãã«ãã³ãã©ã®èšå®
# è£è¶³: èšå®ã«ã¯ã·ã°ãã«çªå·ã§ã¯ãªãã·ã°ãã«åã䜿ãããš
# ã·ã°ãã«åã¯å€§æåã§SIGãã¬ãã£ãã¯ã¹ãªã
# ã·ã°ãã«çªå·ã¯XSIãªãã·ã§ã³ãªã®ã§ç§»æ€æ§ããªã
trap 'sigint_handler' INT
EXITã·ã°ãã«ãã³ãã©ãå®è¡ãããæ¡ä»¶ã®æ確å
EXIT ã·ã°ãã«ãã³ãã©ã¯æ£åžžçµäºæã«å®è¡ãããç䌌ã·ã°ãã«ïŒæ¬åœã®ã·ã°ãã«ã§ã¯ãªãïŒã§ãããã·ã§ã«ã«ãã£ãŠã¯ä»ã®ã·ã°ãã«ã§ç°åžžçµäºãããšãã«ãå®è¡ãããå Žåãããããšæ確ã«ãªããŸããã
$ dash -c 'trap "echo Exit" EXIT; sleep 3'
^C
$ bash -c 'trap "echo Exit" EXIT; sleep 3'
^CExit
$ ksh -c 'trap "echo Exit" EXIT; sleep 3'
^CExit
$ mksh -c 'trap "echo Exit" EXIT; sleep 3'
^CExit
$ yash -c 'trap "echo Exit" EXIT; sleep 3'
^C
$ zsh -c 'trap "echo Exit" EXIT; sleep 3'
^C
æå®ããã·ã°ãã«ã®ãã³ãã©ã ããåºåãã-pãªãã·ã§ã³ã®è¿œå
ãããŸã§ã¯ trap
ã³ãã³ãã«åŒæ°ãäœãæž¡ããã«åŒã³åºãããšã§çŸåšèšå®ãããŠãããã¹ãŠã®ã·ã°ãã«ãã³ãã©ãã·ã§ã«ã«åå
¥åå¯èœãªåœ¢ã§åºåããããšãã§ããŸããã
$ trap "echo int" INT
$ trap "echo quit" QUIT
$ trap
trap -- 'echo int' SIGINT
trap -- 'echo quit' SIGQUIT
ãã®åºåã¯ãçŸåšã®ã·ã°ãã«ãã³ãã©ã®ç¶æ ãäžæŠå€æ°ã«éé¿ããŠãã·ã°ãã«ãã³ãã©ãå€æŽããå ã«æ»ããšãã䜿ãæ¹ãã§ããŸãã
save_traps=$(trap) # çŸåšã®ã·ã°ãã«ãã³ãã©èšå®ã®ä¿å
...ã# ããã§ãªã«ãåŠçããã
eval "$save_traps" # å
ã®ã·ã°ãã«ãã³ãã©èšå®ã®ãªã¹ãã¢
ãã ãããã¹ãŠã®ã·ã°ãã«ãã³ãã©ã®åºåããã§ããªãããå°ã
äžäŸ¿ãªå ŽåããããŸããã-p
ãªãã·ã§ã³ãæå®ãããšãæå®ããã·ã°ãã«ãã³ãã©ã®ã¿ãåºåããããšãã§ããŸãã
$ trap "echo int" INT
$ trap "echo quit" QUIT
$ trap -p INT
trap -- 'echo int' SIGINT
-p
ãªãã·ã§ã³ã¯ãŸã 察å¿ããŠããªãã·ã§ã«ãçµæ§ãããŸããããããããéèŠãªåé¡ã¯ãsave_traps=$(trap)
ã§çŸåšã®ã·ã°ãã«ãã³ãã©ãå€æ°ã«ä¿åã§ããªãã·ã§ã«ããããšããããšã§ããå
·äœçã«ã¯çŸæç¹ã§ã® dashãmkshãzshãOpenBSD sh ã§ããããã¯ã³ãã³ã眮æããµãã·ã§ã«ã«ãã£ãŠå®è¡ããïŒç¡èŠä»¥å€ã®ïŒã·ã°ãã«ãã³ãã©ã®èšå®ããµãã·ã§ã«ã«ç¶æ¿ãããªãããã§ãããµãã·ã§ã«ã«å
¥ããšïŒç¡èŠä»¥å€ã®ïŒã®ã·ã°ãã«ãã³ãã©ãããã©ã«ãã«æ»ãããšã¯ POSIX ã§ãå®çŸ©ãããåäœã§ãããã·ã°ãã«ãã³ãã©ãå€æŽããããšããªãåäžã® trap
ã³ãã³ãã ãã®å Žåã¯æ»ãå¿
èŠããªããšããäŸå€èŠå®ããããŸããããã©ãããŠãçŸåšã®ã·ã°ãã«ãã³ãã©ã®èšå®ãå€æ°ã«ä¿åãããå Žåã¯ãã³ãã³ã眮æã䜿ããã«äžåºŠãã¡ã€ã«ã«åºåãããªã©ã®å¯Ÿçãå¿
èŠã§ãã
ulimit ã³ãã³ã
ulimit
ã³ãã³ãã¯ããã»ã¹ã䜿çšãããªãœãŒã¹ãå¶åŸ¡ããããã®ã³ãã³ãã§ãã
èšå®é ç®ãæå®ããå€æ°ã®ãªãã·ã§ã³ã®è¿œå
次ã®ãããªãªãã·ã§ã³ãè¿œå ãããŸããããããŸã§ã¯ -f
ïŒãã¡ã€ã«ã®æ倧ãµã€ãºïŒããæšæºåãããŠãããããã XSI ãªãã·ã§ã³ã§ãããPOSIX.1-2024 ã§ã¯ XSI ãªãã·ã§ã³ãã BaseïŒåºæ¬æ©èœïŒã«å€æŽãããŸããã
æå³ | |
---|---|
-H |
匷ãå¶éãèšå®ãã |
-S |
匱ãå¶éãèšå®ãã |
-a |
çŸåšã®å¶éãå šãŠè¡šç€ºãã |
-c |
çæãããã³ã¢ãã¡ã€ã«ã®æ倧ãµã€ãº |
-d |
ããŒã¿ã»ã°ã¡ã³ãã®æ倧ãµã€ãº |
-n |
ãªãŒãã³å¯èœãªãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãŒã®æå€§æ° |
-s |
æ倧ã¹ã¿ãã¯ãµã€ãº |
-t |
CPU æéã®æ倧ç§æ°ïŒXSI ãªãã·ã§ã³ïŒ |
-v |
䜿çšå¯èœãªæ倧仮æ³ã¡ã¢ãªé |
ã³ãã³ãã¯äœãå€ãã£ããïŒ
éåžžã·ã§ã«ã«çµã¿èŸŒãŸããããšã¯ãªãå€éšã³ãã³ãã«ã€ããŠã®å€æŽäºé ã§ãã
awk ã³ãã³ã
awk
ã³ãã³ãã¯æååã®ãã¿ãŒã³ãèªèããŠåŠçãè¡ãããã®ããã°ã©ãã³ã°èšèªã§ãã次ã®ãããªäœ¿ãæ¹ãããŸãã
awk -f ã¹ã¯ãªãã [-f ã¹ã¯ãªãã]... [ããŒã¿ãã¡ã€ã« | å€æ°å²åœ]...
awk -f myscript file1.txt var=123 file2.txt var=456 file3.txt
è£è¶³ã§ãããawk ã®æ£èŠè¡šçŸã¯æ¡åŒµæ£èŠè¡šçŸã䜿ããŸãããæŽå²çã« {m}
ã {m,n}
ã«ã¯å¯Ÿå¿ããŠããããPOSIX ã§å®è£
ãèŠæ±ãããŠãããïŒgawk ã åçš Unix ãé€ãïŒäžéšã®å®è£
ã¯é·ãã察å¿ããŠããŸããã§ãããããã nawk ã§ã¯ 20190305 ãããmawk ã§ã¯ 1.3.4 20200717 ãã察å¿ããŠãã 2020 幎é 以éã®ããŒãžã§ã³ã§ããã°åé¡ãªãå©çšå¯èœãšãªã£ãŠããŸããOS ã®ãµããŒãæéãèãããšããå°ã泚æãå¿
èŠã§ãã
$ echo 123 | awk '/[0-9]{3}/'
123
nextfileã¹ããŒãã¡ã³ãã®è¿œå
çŸåšã®å
¥åãã¡ã€ã«ãåŠçãçµäºãã次ã®ãã¡ã€ã«ãèªã¿èŸŒãããã® nextfille
ã¹ããŒãã¡ã³ããæšæºåãããŸããã
$ awk '{ print $0; nextfile }' test1.sh test2.sh test3.sh
#!/bin/sh
#!/bin/sh
#!/bin/sh
fflushé¢æ°ã®è¿œå
æšæºåºåã®ãããã¡ãæžãåºãïŒãã©ãã·ã¥ããïŒfflush
é¢æ°ãæšæºåãããŸããã
# ã³ãã³ãã®åºåãå¥ã®ã³ãã³ãïŒäžèšã®äŸã§ã¯ catïŒã«åºåãããšã
# ãã«ãããã¡ãªã³ã°ãè¡ããããããããã«åºåãããªã
ping google.com | gawk '{ print toupper($0); }' | cat
# ping ã³ãã³ãã®æ¬æ¥ã®åäœã®éãã1ç§ééã§åºåããã
ping google.com | gawk '{ print toupper($0); fflush(); }' | cat
srandé¢æ°ãå©çšããUNIXæéã®ååŸ
ãããŸã§ã¯ srand
é¢æ°ã®åŒæ°ïŒã·ãŒãå€ïŒãçç¥ãããšãã®ããã©ã«ãã®å€ã¯æéã§ããããšãæèšãããŠããŸããããæéãäœã§ãããã¯å®çŸ©ãããŠããŸããã§ãããããã UNIX æéïŒãšããã¯ããã®ç§æ°ïŒã§ããããšãæ確ã«ãªããŸããããã㯠awk
ã³ãã³ãã䜿çšãã UNIX æéã®ååŸã«ç§»æ€æ§ãããããšãæå³ããŠããŸãã
$ awk 'BEGIN { print srand(srand()) }'
ãâïž æ³šæ: ææã§çŽ¹ä»ãããŠããééã£ãæ¹æ³ã
$ awk 'BEGIN { print srand() + srand() }'
GNU awk ãš nawk ãš Busybox awk ã§ã¯ 1ç§ãããŸã
mawk ã§ã¯ææ°åœ¢åŒã§è¡šç€ºãããŸã
ãã®åäœã¯æãã移æ€æ§ããããŸããããæ¯èŒçæ°ãã awk ã®å®è£ ã§ãã goawk 1.27.0 ã§ã¯çŸåšãã®åäœãè¡ã£ãŠããªãã®ã§æ³šæããŠãã ããããããã次ã®ããŒãžã§ã³ãããã§ä¿®æ£ãããã¯ãã§ãã
lengthé¢æ°ã§é åãµã€ãºã®ååŸãå¯èœã«
åŸæ¥ãPOSIX ã§ã¯ length
é¢æ°ã¯æååã®é·ããååŸããé¢æ°ãšããŠããå®çŸ©ãããŠããŸããã§ããããå€ãã®å®è£
ã§é
åã®ãµã€ãºãååŸããããšãå¯èœã§ããããšãããã®æ©èœãæšæºåãããŸããã
$ awk 'BEGIN { a[1]=1; a[2]=2; a[3]=3; print length(a) }'
3
deleteé¢æ°ã§é åã空ã«ããããšãå¯èœã«
åŸæ¥ãPOSIX ã§ã¯ delete
é¢æ°ã¯å€æ°ã®åé€ãè¡ããŸããããé
åããã¹ãŠåé€ããããšã¯ã§ããŸããã§ãããå€ãã®å®è£
ã§é
åãåé€ã§ããããšãããã®æ©èœãæšæºåãããŸããã
$ awk 'BEGIN { a[1]=1; a[2]=2; a[3]=3; delete a; print length(a) }'
0
ãªãããããŸã§ã® awk ã§ã¯æ¬¡ã®ãããªæ¹æ³ã§é åã空ã«ããããšãã§ããŸãã
for (index in ary)
delete ary[index]
# ãŸãã¯
split("", ary)
c99 / c17 ã³ãã³ãïŒCèšèªã³ã³ãã€ã©ïŒ
c99
ããã³ c17
㯠Cèšèªã³ã³ãã€ã©ã§ããCD (C-Language Development Utilities) ãšããŒã¯ãä»ããããŠãããªãã·ã§ã³æ©èœãªã®ã§ãã©ãã«ã§ãã€ã³ã¹ããŒã«ãããŠãããšã¯éããŸããããªãæ©èœã®éãã«ã€ããŠã®è©³çŽ°ã¯èª¿ã¹ãŠããŸããã
c99ã³ãã³ããc17ã³ãã³ããžå€æŽ
c99
ã³ãã³ãã c17
ã³ãã³ãã«å€æŽã«ãªããŸãããPOSIX ã§ã¯ ISO C æšæºãåç
§ããŠãããã³ã³ãã€ã©å㯠POSIX ã®ïŒå€§å¹
ãªïŒæ¹å®æã«ææ°ã® C èšèªæšæºèŠæ Œã«åãããŠå€æŽãããããšã«ãªã£ãŠããŸããã¡ãªã¿ã«ææ°ã® C23 ã¯ãŸã 2024 幎å
¬éäºå®ãšãªã£ãŠããéã«åããŸããã§ãããè¿ãå
¬éãããã§ãããããã次㮠POSIX ã®å€§å¹
ãªæ¹å®ã§ã¯å床 C èšèªã³ã³ãã€ã©ã®ã³ãã³ãåãå€æŽã«ãªãã®ã¯ç¢ºå®ã§ãã
compress / uncompress / zcat ã³ãã³ã
compress
/ uncompress
/ zcat
ã³ãã³ãã¯å§çž®ãšå±éãè¡ãããã®ã³ãã³ãã§ãããããã®ã³ãã³ã㯠XSI (X/Open System Interfaces) ãšããŒã¯ãããŠãããªãã·ã§ã³æ©èœãšãªã£ãŠãã POSIX ã§ã¯å¿
é ã§ã¯ãªãã®ã§ã€ã³ã¹ããŒã«ãããŠããªãã£ããšããŠãäžæè°ã§ã¯ãããŸããããã ã UNIX ã®èªèšŒãååŸããå Žåã«ã¯å¿
é ã§ãã以åã® POSIX ã§ã¯ãã®3ã€ã®ã³ãã³ãã¯å¥ã
ã®ããŒãžã§èª¬æãããŠããŸããããPOSIX.1-2024 ã§ã¯åãããŒãžã«ãŸãšããããŸããã
compressã³ãã³ãã«å±éãè¡ã-dãªãã·ã§ã³ã®è¿œå
ããŒãžã®æ§æãå€ãã£ãŠããã®ã§æ¯èŒãã¥ããã§ãããcompress
ã³ãã³ãã« -d
ãªãã·ã§ã³ãè¿œå ãããŸãããããã¯uncompress
ã³ãã³ãçžåœã®åäœãè¡ãã³ãã³ãã§ãããŸã以åããæšæºåãããŠãã-c
ïŒæšæºåºåãžã®åºåïŒãªãã·ã§ã³ãšäœµçšããããšã§ zcat
ã³ãã³ãçžåœã®åäœãè¡ãããšãã§ããŸããã€ãŸã uncompress
ã³ãã³ããš zcat
ã³ãã³ãã䜿ããã« compress
ã³ãã³ãã ãã§ãã¹ãŠãè¡ãããšãã§ããããã«ãªã£ããšããããšã§ãããããããŒãžãçµ±åãããçç±ã§ãã
-d
ãªãã·ã§ã³ãæå®ãããšãã¯ãé©åãªå±éã¢ã«ãŽãªãºã ã䜿ã£ãŠå
ã®ããŒã¿ã«æ»ãããšããããšã«ãªã£ãŠããã®ã§ãå±éæã®åœ¢åŒã¯èªåå€å®ã§ããå§çž®åœ¢åŒãæå®ãã -g
ãªãã·ã§ã³ã -m
ãªãã·ã§ã³ã¯ãPOSIX ã§ã¯å±éæã«æå®ã§ããªãããšã«ãªã£ãŠããŸãã
ã¡ãªã¿ã«ãå§çž®ã³ãã³ãã -d
ãªãã·ã§ã³ã§å±éã§ããã®ã¯ãïŒPOSIXã§æšæºåãããŠããªãïŒgzip
ãbzip2
ãxz
ãlzma
ãzstd
ãªã©ã§ãåºã䜿ãããŠããäžè¬çãªç¿æ
£ã§ãã
gzipå§çž®åœ¢åŒã䜿çšãã-gãªãã·ã§ã³ã®è¿œå
åŸæ¥ãããã®ã³ãã³ã㯠Z å§çž®åœ¢åŒãæ±ãã³ãã³ããšããŠæšæºåãããŠããŸããããgzip å§çž®åœ¢åŒã䜿çšãã -g
ãªãã·ã§ã³ãè¿œå ãããŸããã-g
ãªãã·ã§ã³ã䜿çšãã gzip å§çž®åœ¢åŒã®å¯Ÿå¿ã¯ãPOSIXã«ããçºæãã§ã¯ãããŸããã1997 幎㮠OpenBSD 2.2 ïŒããã¥ã¡ã³ãã«ã¯ 2.1 ãšæžããŠããïŒïŒã§å®è£
ãããæ©èœã§ãã
ãŸããå±éã«é¢ããŠã¯ uncompress
ã³ãã³ããzcat
ã³ãã³ããšãã« Linux (GNU) ã ãã§ã¯ãªã BSD ãå«ããŠå€ãã®ç°å¢ã§ä»¥åãã gzip 圢åŒã«å¯Ÿå¿ããŠããŸããå±é㯠gzip 圢åŒã«å¯Ÿå¿ããŠããã®ã«ãå§çž®ã¯å¯Ÿå¿ããŠãªããšããé察称ãªç¶æ
ã§ããã
ã¡ãªã¿ã«ããããã®ã³ãã³ããè€æ°ã®å§çž®åœ¢åŒã«å¯Ÿå¿ããã®ã¯ã1 ã€ã®ããšã ããè¡ããšãã UNIX å²åŠçã«åããŠããããšããæèŠãšå
±ã« gzip
ã³ãã³ããæšæºåããã¹ãã ãšããæèŠãå¯ããããŸãããïŒæèŠãèšãã®ãé
ãããã®ã«å ãïŒã7幎åã«ãã§ã«è°è«æžã¿ã®è©±ã§ããæšæºèŠæ Œã®éçºè
ã¯åœæãä»ãæ°ããã³ãã³ããè¿œå ãããããå¥ã®å§çž®åœ¢åŒã«å¯Ÿå¿ããã»ããåªããŠãããšèããŠãããšããçç±ã§åŽäžãããŸãããå®éåé¡ãå§çž®ã¢ã«ãŽãªãºã ãéãã ãã§ãã以å€ã®æ©èœãåãã³ãã³ããããããä¿å®ããŠããããããäžã€ã®ã³ãã³ãã§ç°ãªãå§çž®ã¢ã«ãŽãªãºã ããµããŒãããã»ãããå©çšè
ã«ãšã£ãŠãéçºè
ã«ãšã£ãŠãã·ã³ãã«ã§ç°¡åã§ãã1 ã€ã®ããšã¯ã©ã€ãã©ãªé¢æ°ã¬ãã«ã§ããã°ååã§ãããç°ãªãã¢ã«ãŽãªãºã ã®åŠçãå¥ã®ã³ãã³ãã«åé¢ããããã°ãã³ãã³ãå
éšããå¥ã®ã³ãã³ããåŒã³åºãã°ããã ãã§ããPOSIX ã¯ã€ã³ã¿ãŒãã§ãŒã¹ãèŠå®ãããã®ã§ãã£ãŠã³ãã³ãã®å
éšå®è£
ãèŠå®ããŸããã
æ°ããªåœ¢åŒã«æ¡åŒµå¯èœãª-mãªãã·ã§ã³ã®è¿œå
POSIX ã§æšæºåãããŠãã察å¿åœ¢åŒã¯åŸæ¥ã® Z 圢åŒãš gzip 圢åŒã®ã¿ã§ããå§çž®åœ¢åŒã®æå®ã¯ gzip 圢åŒãæå®ãã -g
ãªãã·ã§ã³ã®ä»ã« -m
ãªãã·ã§ã³ãè¿œå ãããŸããã-m algo
ãšããæå®æ¹æ³ã§åŒæ° (algo) ã«å§çž®åœ¢åŒãæå®ããŸãã
Algorithm | algo | Filename Suffix |
---|---|---|
Adaptive LZW | lzw | .Z |
RFC1951 DEFLATE | deflate | .gz |
Synonym for DEFLATE | gzip | .gz |
-m
ãªãã·ã§ã³ã¯ãããŸã§ã®å®è£
ã«ã¯ååšããªãã£ããªãã·ã§ã³ã§ããPOSIX ã«ããçºæã«ããã«æãããããããŸãããããæ°ããæ©èœããçºæããããã§ã¯ãªããä»ãŸã§ã® (OpenBSD compress ã®) æ©èœã«å¥ã®ãªãã·ã§ã³ãå®çŸ©ããã ããšããæ±ãã§ããæ¢åã®æ©èœãšã»ãŒåãæ©èœã®ãªãã·ã§ã³ã POSIX ãè¿œå ãããšããããšã¯ãããŸãïŒxargs
ã³ãã³ãã«ããã -l
ãªãã·ã§ã³ãæšæºåã -L
ãªãã·ã§ã³ãªã©ïŒã
-m
ãªãã·ã§ã³ãè¿œå ããçç±ã¯ãæ¢åã® uncompress
ã³ãã³ãã zcat
ã³ãã³ãã®å®è£
ãè€æ°ã®åœ¢åŒã«å¯Ÿå¿ããŠãããšããçŸç¶ãèžãŸããŠããã®äžè¬çãªæ
£ç¿ã compress
ã³ãã³ãã«ãåãå
¥ããããã§ããã€ãŸãæ°ããªå§çž®åœ¢åŒã«å®è£
ã察å¿ã§ããäœå°ãäžããããã«çšæããããã®ã§ãã-m
ãªãã·ã§ã³ã®å°å
¥ã«ããæ¡åŒµæ§ãåäžããŸãããæ°ããå§çž®åœ¢åŒãžã®å¯Ÿå¿ãäžè¬çã«ãªãã°ãå°æ¥ã® POSIX ã§æšæºåããããããããŸãããä»åŸã¯ãããã®ã³ãã³ãã¯è€æ°ã®å§çž®åœ¢åŒãåãæ¹æ³ã§æ±ãããã®ããã³ããšã³ãã³ãã³ããšããäœçœ®ã¥ãã«ãªãã§ãããã
date ã³ãã³ã
date
ã³ãã³ãã¯ã·ã¹ãã æ¥æã®ååŸãšèšå®ãè¡ãã³ãã³ãã§ããã·ã¹ãã æ¥æã®èšå®ã«éã XSI ãªãã·ã§ã³æ©èœã§ãã
UNIXæéïŒ%sïŒãªã©ã®æžåŒãžã®å¯Ÿå¿
ãããŸã§æ¬ ããŠãã %s
ãªã©ã®æžåŒã«å¯Ÿå¿ããããã«ãªããŸããããŸã date
ã³ãã³ãã察å¿ãã¹ãæžåŒã¯ãdate
ã³ãã³ãã§å®çŸ©ãããã®ã§ã¯ãªã Cèšèªã® strftime()
é¢æ°ã§å®çŸ©ãããããã«å€æŽã«ãªããä»ãŸã§ã® date
ã³ãã³ãã§å¯Ÿå¿ããŠããæžåŒä»¥äžã®ãã®ã䜿ããããã«æšæºåãããŠããŸãã
åé¿ç: UNIXæéãšæ¥æã®çžäºå€æãææ¥ã®ååŸé¢æ°
date
ã³ãã³ãã® +%s
æžåŒã¯ãã§ã«å€ãã®ç°å¢ã§å®è£
ãããŠããŸãããããæ°ã«ãªãå Žåã¯ãUNIX æéãååŸããã·ã§ã«é¢æ°ããã³ãæ¥åžžã®æ¥ä»ãšUNIXæéãçžäºã«å€æããã·ã§ã«é¢æ°ãäœã£ãŠããã®ã§ãã¡ãã䜿çšããŠãã ããã
dd ã³ãã³ã
dd
ã³ãã³ãã¯ãã¡ã€ã«ã®å€æãšã³ããŒãè¡ãã³ãã³ãã§ãããã£ã¹ã¯ãåæåãããããã®ã«äœ¿çšãããããå±éºãªã·ã¹ãã 管çç³»ã®ã³ãã³ããšåéããããããšããããŸããã/dev/sda
ã®ãããªããã€ã¹ãžã®æžã蟌ã¿ã¯ root æš©éãããã° cp
ã³ãã³ãã§ãã§ããããã§ãdd
ã³ãã³ããç¹å¥å±éºãªããã§ã¯ãããŸãããã³ãã³ãã©ã€ã³åŒæ°ã®æžåŒãç¹åŸŽçã§ããä»ã®ã³ãã³ããšå¯ŸããŠéããã®ã§ã¯ãããŸãããã¡ãªã¿ã« dd
ã³ãã³ãã®åŒæ°ãç¹åŸŽçãªã®ã¯ãå
㯠Unix ãšã¡ã€ã³ãã¬ãŒã ãšã®éã§ã®ããŒã¿äº€æçšã®ã³ãã³ãã§ãã¡ã€ã³ãã¬ãŒã ã®ãžã§ãå¶åŸ¡èšèªïŒJCLïŒã® DD æã«ç±æ¥ããŠãããããšèšãããŠããŸãã
ãã¹ãŠã®ããŒã¿ã確å®ã«èªã¿èŸŒãiflag=fullblock
iflag=fullblock
ã¯å
¥åã®ãããã¯ããã£ã±ãã«ãªããŸã§èç©ããŠããåŠçãå®è¡ããããã®ãã©ã°ã§ããiflag=fullblock
ãæå®ããã« count=
ãæå®ããŠãã€ãããããŒã¿ãèªã¿åããšããŒã¿ãéåããå ŽåããããŸãããã®ãã©ã°ã®å¹æã¯æ¬¡ã®ãããªäŸã§ç¢ºèªããããšãã§ããŸãã
$ cat /dev/urandom | dd bs=1048576 count=1 | wc -c
0+1 records in
0+1 records out
65536 bytes (66 kB, 64 KiB) copied, 0.000959738 s, 68.3 MB/s
65536
$ cat /dev/zero | dd bs=1048576 count=1 iflag=fullblock | wc -c
1048576
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00114991 s, 912 MB/s
äžèšã®ã³ãŒãã§ã¯ /dev/zero
ã®äžèº«ããã€ã㧠dd
ã³ãã³ãã«æž¡ããŠããŸãããåè
㯠bs
ã§æå®ãã 1 MB ã§ã¯ãªã 64 KB ãèªã¿åã£ãã ãã§çµäºããŠããŸããèªã¿åã£ãããŒã¿ããã€ãã§ããã« wc
ã³ãã³ãã«æž¡ããŠããŸãããåœç¶ãã® wc
ã³ãã³ããåŠçããããŒã¿ãµã€ãºã 64 KB ã§ããäžæ¹åŸè
㯠iflag=fullblock
ã®æå®ã«ãã 1 MBæºãŸããŸã§ãŸã£ãŠããåŠçãè¡ããããæå®ãããµã€ãºã確å®ã«èªã¿åãããšãã§ããŸãããã®æ±ºããåããéããã€ãããã®å
¥å㯠iflag=fullblock
ãæå®ããªããããèªã¿åããä¿èšŒã¯ãããŸãããbs=1 count=1024
ãšæå®ããããšã§æå®ããæ£ç¢ºãªãã€ãæ°èªã¿èŸŒãããšãã§ããŸããã1ãã€ããã€ã®èªã¿èŸŒã¿ã«ãªãã®ã§åœç¶åŠçã¯é
ããªããŸãããã®åé¡ã¯ POSIX.1-2024 ã§ã説æãããŠããŸãã
Using the
count=
operand ofdd
with a pipe or FIFO as the input can lead to surprising results, since these file types are prone to encountering short reads for any input block size other than 1. Unless theiflags=fullblock
operand is in effect,dd
will stop after the specified number of reads, rather than full input blocks, and therefore can often result in fewer bytes being output than the product of the count and input block size.
èš³ ãã€ããŸã㯠FIFO ãå
¥åãšã㊠dd
ã® count=
ãªãã©ã³ãã䜿çšãããšããããã®ãã¡ã€ã«ã¿ã€ãã§ã¯ã1
以å€ã®å
¥åãããã¯ãµã€ãºã§çãèªã¿åããçºçãããããããé©ããããªçµæã«ãªãããšããããiflags=fullblock
ãªãã©ã³ããæå¹ã§ãªãéã dd
ã¯å®å
šãªå
¥åãããã¯ã§ã¯ãªãæå®ãããèªã¿åãåæ°ã§åæ¢ãããããåºåããããã€ãæ°ã¯ãcount
ãšå
¥åãããã¯ãµã€ãºã®ç©ãããå°ãªããªãããšãããããã
泚æ iflags
㯠POSIX æšæºèŠæ Œã®ã¹ãã«ãã¹ã§æ£ãã㯠iflag
ã§ããiflags
ãæã£ãå®è£
ã¯ååšããŸããããã®ã¹ãã«ãã¹ã¯ä¿®æ£ãããã¯ãã§ãã
ã¡ãªã¿ã« dd
ã³ãã³ãã䜿çšããŠæå®ãããã€ãæ°ãèªã¿èŸŒãã®ã§ããã°ãPOSIX.1-2024 ã§æšæºåããã tail -c
ã䜿çšããã»ããè¯ãã§ãããããã®åé¡ã¯ããdd bs=ãµã€ãº count=1ã㧠ãã€ãããå
¥åãããšããŒã¿ãéåããçœ ã«æ³šæããïŒãã§ã詳ãã解説ããŠããŸãã
å°æ¥ã®æ¹åæ§: SIGINFO ãžã®å¯Ÿå¿
Linux ã® dd
ã³ãã³ã㯠USR1 ã·ã°ãã«ãéä¿¡ãããšè»¢éããŒã¿ã®ã¹ããŒã¿ã¹ãåºåããããšãã§ããŸãã
$ dd if=/dev/random of=/dev/null bs=1024 count=10000000 &
[1] 1437922
$ kill -s USR1 $!
929781+0 records in
929780+0 records out
952094720 bytes (952 MB, 908 MiB) copied, 3.53758 s, 269 MB/s
FreeBSD ã§ã¯ USR1 ã·ã°ãã«ã®ä»£ããã« INFO ã·ã°ãã«ã䜿çšããŸãã
$ dd if=/dev/random of=/dev/null bs=1024 count=10000000 &
$ kill -s INFO $!
430270+0 records in
430270+0 records out
440596480 bytes transferred in 1.933599 secs (227863429 bytes/sec)
çŸåšã® Linux ïŒãããããã System V ç³» UnixïŒã«ã¯ INFO ã·ã°ãã«ã¯å®è£
ãããŠããŸãããå°æ¥ã®æ¹åæ§ãšã㊠POSIX ã§ã¯ BSD ç³» Unix ã«ååšãã INFO ã·ã°ãã«ãæšæºåããdd
ã³ãã³ãã¯ããã«å¯Ÿå¿ããããšãæèšãããŠããŸãã
find ã³ãã³ã
find ã³ãã³ãã¯ãã¡ã€ã«ãæ€çŽ¢ããèŠã€ãããã¡ã€ã«åã®åºåããã³èŠã€ãããã¡ã€ã«ã«å¯ŸããŠïŒ-exec
ã䜿ã£ãŠæå®ããïŒä»»æã®ã³ãã³ããå®è¡ããããã®ã³ãã³ãã§ãã
find ... æ€çŽ¢æ¡ä»¶ ... -exec ä»»æã®ã³ãã³ã +
倧æåãšå°æåãåºå¥ããªã-inameè©äŸ¡åŒã®è¿œå
-name
ãšåãã§ãã倧æåãšå°æåãåºå¥ããŸããã
ç°ãªããã¡ã€ã«ã·ã¹ãã ãé€ã-mountè©äŸ¡åŒã®è¿œå
以åãã POSIX ã§æšæºåãããŠãã -xdev
è©äŸ¡åŒãšäŒŒãæ©èœãæ〠-mount
è©äŸ¡åŒãè¿œå ãããŸãããGNU findã§ã¯ -mount
㯠-xdev
ã®å¥åã§ãããšæžãããŠããŸãããPOSIX ã§æšæºåãããå
容ã«ã¯ãããã«éãããããŸãã现ããæ€èšŒã¯ããŠããªãã®ã§è©³çŽ°ã¯èª¿ã¹ãŠãã ããã
ãã«æåçµç«¯ã§åºåãã-print0è©äŸ¡åŒã®è¿œå
æ€çŽ¢ãããã¡ã€ã«åãæ¹è¡çµç«¯ã§ã¯ãªããã«æåçµç«¯ã§åºåããè©äŸ¡åŒã§ããxargs -0
ã read -d ""
ãªã©ã§èªã¿èŸŒãããšãã§ããŸãã
fort77 ã³ãã³ãïŒFortran 77ã³ã³ãã€ã©ïŒã®åé€
Fortran 77 ã®ã³ã³ãã€ã©ã§ãã以åã® POSIX ã§ã¯ FD (FORTRAN Development Utilities) ãšããŒã¯ãä»ããããŠãããªãã·ã§ã³æ©èœã§ãå®è£ ã¯å¿ é ã§ã¯ãããŸããã§ããããã®ã³ãã³ã㯠POSIX.1-2024 ã§åé€ãããŸãããPOSIX.1-2024 ã«å¯Ÿå¿ãã Fortran ã³ã³ãã€ã©ãååšããªãããã®ããã§ãã
gettext / ngettext / xgettext / msgfmt ã³ãã³ãïŒæ°èŠïŒ
gettext
/ ngettext
/ xgettext
/ msgfmt
ã³ãã³ã㯠POSIX.1-2024 ã§æ°ããè¿œå ãããåœéåé¢ä¿ã®ã³ãã³ãã§ããgettext
ãngettext
ãmsgfmt
㯠POSIX ã§å¿
é ã³ãã³ããšãªã£ãŠããããšã«æ³šæããŠãã ãããã€ãŸã gettext ã¯ãã¯ã GNU ã Linux ã ãã®ãã®ã§ã¯ãããŸããã
gettext ç±æ¥ã®æ°ããåœéå察å¿
åŸæ¥ POSIX ã§ã¯ catgets ã®ä»çµã¿ã䜿ã£ãåœéåæ©èœã POSIX.1-2001 㧠XSI æ¡åŒµæ©èœãšããŠè¿œå ãããPOSIX.1-2008 ã§åºæ¬æ©èœãšãªã£ãŠããŸãããè£è¶³ã§ããã« catgets ã§ç¿»èš³ãè¡ãã«ã¯ POSIX ã§ãæšæºåãããŠãã gencat
ã³ãã³ãã䜿ã£ãŠç¿»èš³ãã¡ã€ã«ãäœæããŸããXSI æ¡åŒµæ©èœã§ããããšãããããããã«ãå
㯠System V ç³» Unix ã§åºã䜿ãããŠããåœéåæ©èœã§ããPOSIX.1-2024 ã§ã¯å¥ã®ä»çµã¿ã§ãã gettext ã䜿ã£ãåœéåæ©èœãè¿œå ãããŸãããgettext ã¯å
ã¯ãµã³ã»ãã€ã¯ãã·ã¹ãã ãºã§éçºãããåœéåæ©èœã§ãããçŸåšã¯ GNU gettext ãšã㊠GNU é¢é£ã®ã³ãã³ãã Linux ãªã©ã§åºã䜿ãããŠããŸãããããã®åœéåæ©èœã¯ã·ã§ã«ã¹ã¯ãªããéå®ã®æ©èœã§ã¯ãªããã©ã¡ãããšèšãã° C èšèªããã®ä»ã®èšèªã®ããã®ä»çµã¿ã§ããããšã«æ³šæããŠãã ããã
äœè«ã§ãããgettext ã®æšæºå㯠2021幎10æã«äº¡ããªã£ã Joerg SchillingïŒcdrtools ã Schily Bourne Shell ã®éçºè ïŒããPOSIX ã«ããã°ã©ã ãè¿œå ããã®ã«ã©ã®ãããªåŽåãå¿ èŠãªã®ããç解ããŠãããããã« Hasso Plattner Institute ã®åŠçãšäžç·ã« POSIX æšæºèŠæ Œã®ææ¡ãæžããããã§ãããªããªãé¢çœãè©Šã¿ã§ããã詳现ã¯ä»¥äžãåç §ããŠãã ããã
- https://unix.stackexchange.com/questions/614808/why-is-there-no-mktemp-command-in-posix
- Jörg Schilling is gone
- https://web.archive.org/web/20211018130448/https://www.opengroup.org/austin/
èšèªç¿»èš³ã® gettext / ngettext ã³ãã³ã
gettext
ã³ãã³ããš ngettext
ã³ãã³ãã¯ãè±èªã®ã¡ãã»ãŒãžãåŒæ°ã«ïŒç¿»èš³ãã¡ã€ã«ãããã°ïŒããã«å¯Ÿå¿ãã翻蚳ã¡ãã»ãŒãžãåºåããã³ãã³ãã§ããã¡ãªã¿ã« ngettext
ã³ãã³ãã¯æ°å€ã®åæ°åœ¢ãšè€æ°åœ¢ã§ç°ãªã翻蚳ã¡ãã»ãŒãžã«å€æããããšãã§ããã³ãã³ãã§ãã
翻蚳ãã¡ã€ã«ãçæãã xgettext / msgfmt ã³ãã³ã
xgettext
ã³ãã³ããš msgfmt
ã³ãã³ãã¯ç¿»èš³ãã¡ã€ã«ãäœæããããã®ã³ãã³ãã§ããxgettext
ã³ãã³ãã¯ãœãŒã¹ã³ãŒããã翻蚳察象ã®æååãæœåºã㊠PO ãã¡ã€ã«ãäœæããã³ãã³ãã§ããPOSIX ã§ã¯ CD (C-Language Development Utilities) ãšããŒã¯ãä»ããããŠãããC èšèªçšã®éçºçšã³ãã³ããšã㊠C èšèªã®ããšããèæ
®ãããŠããŸããããã ãå®éã® GNU xgettext
ã³ãã³ãã¯ã·ã§ã«ã¹ã¯ãªãããå«ãããŸããŸãªèšèªã®ãœãŒã¹ã³ãŒãã«å¯Ÿå¿ããŠããŸããPOSIX ã® xgettext
㯠C èšèªå°çšã§ãããåœéåã«ã¯ããã¹ããã¡ã€ã«åœ¢åŒã® PO ãã¡ã€ã«ããããã°ããã®ã§ãã·ã§ã«ã¹ã¯ãªããã§ã移æ€æ§ããã圢ã§åœéå察å¿ãè¡ãããšã¯å¯èœã§ãã
msgfmt
ã³ãã³ã㯠xgettext
ã³ãã³ãããçæãã PO ãã¡ã€ã«ïŒãå
ã«ç¿»èš³ãããã¡ã€ã«ïŒãããMO ãã¡ã€ã«ãçæããã³ãã³ãã§ããMO ãã¡ã€ã«ã¯ãã€ããªåœ¢åŒã§ã·ã¹ãã äŸåããå¯èœæ§ããããããïŒã€ã³ã¹ããŒã«æãªã©ã«ïŒç°å¢ããšã«çæããå¿
èŠããããŸããéçºæã®ã¿ã«äœ¿ãã³ãã³ãã§ã¯ãªããããªãã·ã§ã³ã§ã¯ãªãå¿
é ã³ãã³ããšãªã£ãŠããŸãã
åé¿ç: ã·ã§ã«ã¹ã¯ãªããçšã®åœéåã©ã€ãã©ãªsh-i18n
ã·ã§ã«ã¹ã¯ãªããã®åœéåã¯åŸæ¥ã® catgets ã®ä»çµã¿ã«ã¯ ksh93 ã®ã¿ã察å¿ããŠããŸãããGNU gettext ã䜿ã£ã翻蚳ã®ä»çµã¿ã¯ bash ããã€ãã£ãã«å¯Ÿå¿ïŒbash å°çšã® $"..."
ã䜿çšããŠç¿»èš³ããŸãïŒããŠããŸããããã®æ¹æ³ã¯çŸåšéæšå¥šã§ãGNU ãæäŸãã gettext.sh
ã·ã§ã«é¢æ°ã©ã€ãã©ãªã䜿çšããæ¹æ³ãæšå¥šãããŠããŸãããã® gettext.sh
ã·ã§ã«é¢æ°ã©ã€ãã©ãªã§ã¯å
éšçã« gettext
ã³ãã³ãã ngettext
ã³ãã³ãã䜿çšããŠããŸãããã ãå
éšã§ïŒPOSIX ã§æšæºåãããŠããªãïŒenvsubst
ã³ãã³ãã䜿çšããŠããã gettext.sh
ã·ã§ã«é¢æ°ã©ã€ãã©ãªã¯ POSIX ã³ãã³ãã ãã§ã¯åäœããŸããã
ãã®ãããªçŸç¶ã§ããããã移æ€æ§ãããã·ã§ã«ã¹ã¯ãªããã§åœéå察å¿ãè¡ãã®ã¯é£ããç¶æ³ã§ããããã§ç§ãã·ã§ã«ã¹ã¯ãªããçšã®åœéå察å¿ã·ã§ã«é¢æ°ã©ã€ãã©ãªã§ãã sh-i18n ãäœæããŠããŸãããã®ã·ã§ã«é¢æ°ã©ã€ãã©ãªã¯ãgettext.sh
ã gettext
ã³ãã³ãã ngettext
ã³ãã³ããçŽæ¥äœ¿ããããã䜿çšæ¹æ³ãç°¡åã§ããã¹ãŠã® POSIX ã·ã§ã«ããµããŒãããŠããé«ã移æ€æ§ãããïŒäŸãã° gettext
ã ngettext
ã³ãã³ããã€ã³ã¹ããŒã«ãããŠããªãç°å¢ã§ã翻蚳ãã§ããªãã ãã§åäœããïŒã®ã§ãããã·ã§ã«ã¹ã¯ãªããã§åœéå察å¿ãããããšãã人ã¯ãããã䜿çšãããšããã§ãããã
sh-i18n ã¯å
éšçã« gettext
ã³ãã³ãã ngettext
ã³ãã³ãã䜿çšããŠç¿»èš³ããŠããŸãããããã£ãŠç¿»èš³ãã¡ã€ã«ãäœãã«ã¯ xgettext
ã³ãã³ããš msgfmt
ã³ãã³ãã䜿ããŸãã
head ã³ãã³ã
head
ã³ãã³ãã¯ãã¡ã€ã«ã®åé éšåãåºåããã³ãã³ãã§ãã
èªã¿èŸŒããã€ãæ°ãæå®ãã-cãªãã·ã§ã³ã®è¿œå
ãã¡ã€ã«ã®æåããæå®ãããã€ãæ°ãåºåãã -c
ãªãã·ã§ã³ãæšæºåãããŸãããhead
ã³ãã³ãã¯ååãšããŠããã¹ããã¡ã€ã«ãæ±ãã³ãã³ãã§ããã-c
ãªãã·ã§ã³ãæå®ããå Žåã¯ãã€ããªããŒã¿ãšããŠæ±ãããšãæèšãããŠããŸãã
$ echo 1234567890 | head -c 5
12345
泚æ: AIX ã§ã¯æ«å°Ÿã«æ¹è¡ãè¿œå ããã
ã¡ãªã¿ã« tail
ã³ãã³ãã¯ä»¥åãã -c
ãªãã·ã§ã³ãæšæºåãããŠããŸããhead
ã³ãã³ããš tail
ã³ãã³ãã®æ©èœã察ç
§çã§ã¯ãªãã®ã¯ããããããã® 2 ã€ã®ã³ãã³ãã¯ã«ãŒããç°ãªãå¥ã
ã®å Žæã§éçºãããŠããããã§ããhead
ã³ãã³ã㯠sed
ã³ãã³ãã§ä»£æ¿ã§ãã (head -n 5
= sed 5q
) ãããResearch UnixïŒUnix ã®åµå§è
éã®ãªãªãžãã«ã® UnixïŒã§ã¯ãé·ããäžèŠãªãã®ãšããŠèããããŠããŸããããã®è©±ã«ã€ããŠã¯å¥ã®æ©äŒã«çŽ¹ä»ããããšæããŸãã
logger ã³ãã³ã
logger
ã³ãã³ãã¯ã·ã¹ãã ãã°ã«ã¡ãã»ãŒãžãæžã蟌ãã³ãã³ãã§ãã
è¿œå æ å ±ãèšé²ãã -f, -i, -p, -t ãªãã·ã§ã³ã®è¿œå
ãããŸã§ POSIX ã§æšæºåãããŠãã logger
ã³ãã³ãã«ã¯ãªãã·ã§ã³ã¯äžåãªããã¡ãã»ãŒãžã®ã¿ãæå®ã§ããŸããã
æå³ | |
---|---|
-f file |
æå®ãããã¡ã€ã«ã®å 容ããã°ã«åºå |
-i |
logger ã®ããã»ã¹ ID ããã°ã«åºå |
-p priority |
åªå 床ïŒerrãwarningãinfoãdebug ãªã©ïŒããã°ã«åºå |
-t tag |
ïŒãŠãŒã¶ãŒåã®ä»£ããã«ïŒã¿ã°ã§æå®ããæååãåºå |
mailx ã³ãã³ã
mailx
ã³ãã³ãã¯ã¡ãŒã«ãéä¿¡ããããå±ããã¡ãŒã«ãé²èŠ§ããããã®ã³ãã³ãã§ããå®éã® mailx
ã³ãã³ãã¯ã¡ãŒã«ãé²èŠ§ããæ©èœãæã£ãŠãããšæããŸãããPOSIX ã§ã¯é²èŠ§æ©èœã¯ UP (User Portability Utilities) ãšæå®ãããŠãããªãã·ã§ã³ã§ãé²èŠ§æ©èœã®å®è£
ãå¿
é ãªã®ã¯ User Portability Utilities ããµããŒãããŠããã·ã¹ãã ã®ã¿ã§ãã
空ã¡ãŒã«ãéä¿¡ããªã-Eãªãã·ã§ã³ã®è¿œå
ãã®ãªãã·ã§ã³ã¯ããã°ã©ã ããã¡ãã»ãŒãžãçæããŠãã€ãçµç±ã§ mailx
ã³ãã³ãã«æž¡ããŠã¡ãŒã«éä¿¡ããåŠçã§ããšã©ãŒã®å Žåã«ã¡ãŒã«ãéä¿¡ããªãæ¹æ³ãšããŠå©çšããããšãã§ããŸããã€ãŸããšã©ãŒã®å Žåã¯ã¡ãã»ãŒãžãäœãåºåããªãããšã§ã¡ãŒã«ã®éä¿¡ããã£ã³ã»ã«ãããŸãã
make ã³ãã³ã
make
ã³ãã³ãã¯ç¹å®ã®ãã¡ã€ã«ããå¥ã®ãã¡ã€ã«ãçæãããšãã«äœ¿çšããã³ãã³ãã§ããSD (Software Development Utilities) ãšããŒã¯ãä»ããããŠãããªãã·ã§ã³æ©èœãªã®ã§ãã©ãã«ã§ãã€ã³ã¹ããŒã«ãããŠãããšã¯éããŸãããããã«æãããã®ä»¥å€ã«ããããããªæ©èœãè¿œå ãããŠããã®ã§è©³ãã㯠POSIX ãåç
§ããŠãã ããã
䞊åå®è¡ã®ããã®-jãªãã·ã§ã³ã®è¿œå
䞊åå®è¡ã®ããã® -j
ãªãã·ã§ã³ãæšæºåãããŸãããé¢é£ã㊠.NOTPARALLEL
ãš .WAIT
ç¹æ®ã¿ãŒã²ãããè¿œå ãããŠããŸãã
ãã¡ã€ã«åã§ãªãããšãæ瀺ãã.PHONYç¹æ®ã¿ãŒã²ããã®è¿œå
ã¿ãŒã²ããããã¡ã€ã«åããã£ã¬ã¯ããªåã§ãªãããšãæ瀺ãã .PHONY
ç¹æ®ã¿ãŒã²ããã®è¿œå ãããŸããã
ps ã³ãã³ã
ps
ã³ãã³ãã¯ããã»ã¹ã®ã¹ããŒã¿ã¹ãå ±åããã³ãã³ãã§ãããã®ã³ãã³ã㯠XSI ãªãã·ã§ã³ãšãªã£ãŠããã³ãã³ãã©ã€ã³ãªãã·ã§ã³ãå€ãã移æ€æ§ã«ã¯æ³šæãå¿
èŠã§ãã
åºãå¹ ã§è¡šç€ºãã-wãªãã·ã§ã³ã®è¿œå
äžè¡ãããåºãå¹
ã§è¡šç€ºãã -w
ãªãã·ã§ã³ãæšæºåãããŸããã
Batch Environmenté¢é£ã®ã³ãã³ãã®åé€
POSIX 2d-1994 ã§è¿œå ããã Batch Environment é¢é£ã®ã³ãã³ããåé€ãããŸããã
qalter qdel qhold qmove qmsg qrerun
qrls qselect qsig qstat qsub
åé€çç±ãæ確ã«æžããŠããæãèŠã€ããŠããªãã®ã§ãããã»ãŒééããªãå®éã«ã¯äœ¿ãããŠããªãã³ãã³ãã ããã§ãããã
readlink / realpath ã³ãã³ãïŒæ°èŠïŒ
readlink
ã³ãã³ããš realpath
ã³ãã³ã㯠POSIX.1-2024 ã§æ°ããè¿œå ãããã³ãã³ãã§ãã
ã·ã³ããªãã¯ãªã³ã¯å ãååŸããã³ãã³ãã®è¿œå
åºãç°å¢ã§å®è£
ãããã©ã®ç°å¢ã«ã§ããããšèšã£ãŠãéèšã§ã¯ãªãã³ãã³ããšãªã£ã readlink
ã³ãã³ããš realpath
ã³ãã³ããæšæºåãããŸãããã©ã¡ãã䌌ããããªæ©èœãæã£ãŠããŸãããPOSIX ã§æšæºåããããã®äºã€ã®ã³ãã³ãã®éãã¯æ確ã§ã³ãã³ãåã®ãšãããšãªã£ãŠããŸãã
-
readlink
ã»ã»ã» ã·ã³ããªãã¯ãªã³ã¯ã®äžèº«ãèªã¿åã- ãªãã·ã§ã³
-n
ã®ã¿
- ãªãã·ã§ã³
-
realpath
ã»ã»ã» ã·ã³ããªãã¯ãªã³ã¯ãååž°çã«è§£æ±ºãå®äœã®ãã¹ãååŸãã- ãªãã·ã§ã³
-e
ã-E
ã®ã¿
- ãªãã·ã§ã³
æŽå²çã«ãã®äºã€ã®ã³ãã³ãã¯ç°ãªãã«ãŒããæã€ã³ãã³ãã§å¥ã
ã®å Žæã§èªçãæ©èœã匷åãããŠããŸãããrealpath
ã³ãã³ã㯠BSD ã§äœ¿ãããŠããã³ãã³ãã§ãreadlink
ã³ãã³ã㯠Linux ã§äœ¿ãããŠããã³ãã³ãã ãšåéããããããšããããŸãããããã¯çå®ã§ã¯ãããŸãããrealpath
ã readlink
ãåçŽãªæ©èœãªã®ã§åããããªãã®ãäœåºŠãåçºæãããŠããããã§ããrealpath
ã³ãã³ã㯠1996 幎åœæ dwww ããã±ãŒãžã®äžéšãšããŠå©çšå¯èœã§ãã£ããã®ãã2002 幎㫠Debian 3.0 ã§åç¬ã®ããã±ãŒãžãšããŠã€ã³ã¹ããŒã«å¯èœã«ãªããŸããããã®ãšãã«ã¯ BSD ïŒOpenBSD ãš NetBSDïŒã§ã¯ readlink
ã³ãã³ããç»å ŽããŠããŸãããrealpath
ãæãã BSD ã§äœ¿ããã®ã¯ FreeBSD ã ãã§ããBSD ãšèšã£ããšãã« FreeBSD ã®ããšããèããŠããªãã®ã¯å€ãã®äŸã§èŠãããŸãã
Year | realpath | readlink |
---|---|---|
1996 | dwww ããã±ãŒãžã®äžéš | |
1997 | OpenBSD 2.1, OpenBSD 2.2 (-f) | |
2001 | FreeBSD 4.3 | |
2002 | Debian 3.0 | NetBSD 1.6 |
2003 | GNU Coreutils 4.5.5 (-f) | |
2004 | FreeBSD 4.10 | |
2007 | NetBSD 4.0 (-f) | |
2012 | GNU Coreutils 8.15 | FreeBSD 8.3 (-f), Mac OS X 10.8 |
2022 | OpenBSD 7.1, macOS 13.0 | macOS 12.3 (-f) |
2023 | NetBSD 10 |
readlink
ã³ãã³ãã® -f
ãªãã·ã§ã³ïŒGNU ã ãã§ã¯ãªã macOS ãªã©ã§ã察å¿ããïŒã¯ realpath
ã³ãã³ããšåçã®åäœãè¡ããŸãã POSIX ã§ã¯æšæºåãããŠããŸãããPOSIX ã®ç¯å²ã§ã·ã³ããªãã¯ãªã³ã¯ã解決ãããå Žåã«äœ¿ãã³ãã³ã㯠realpath
ã§ãã
åé¿ç: POSIXã³ãã³ãã®ã¿ã䜿ã£ãreadlink -fã®å®è£
realpath
ã³ãã³ãïŒãŸã㯠readlink -f
ïŒã¯ã·ã§ã«ã¹ã¯ãªããã®å®äœã®å ŽæãèŠã€ããããã«å¿
èŠãªã³ãã³ãã§ãããã®ã³ãã³ããæšæºåãããŠãããã以åã®ç°å¢ã§ã¯æšæºã€ã³ã¹ããŒã«ãããŠããªãå Žåããã£ãããã以åã® POSIX ã§æšæºåãããç¯å²ã®æ©èœïŒls
ã³ãã³ãïŒã®ã¿ã䜿ã£ãŠ readlinkf
ã·ã§ã«é¢æ°ãå®è£
ããŠããŸããã»ãšãã© readlink -f
ãšäºæã®åäœãè¡ãã·ã³ããªãã¯ãªã³ã¯ã埪ç°åç
§ããŠããå Žåã®ãšã©ãŒåŠçã«ã察å¿ããŠããŸããããå¿
èŠãªæ¹ã¯ããã䜿çšããŠãã ããã
rm ã³ãã³ã
rm
ã³ãã³ãã¯ãã¡ã€ã«ãŸãã¯ãã£ã¬ã¯ããªãåé€ããããã®ã³ãã³ãã§ãã
空ã®ãã£ã¬ã¯ããªãåé€å¯èœã«ãã-dãªãã·ã§ã³ã®è¿œå
rm
ã³ãã³ãã« -d
ãªãã·ã§ã³ãè¿œå ãããŸããã -d
ãªãã·ã§ã³ãæå®ãããšåŒæ°ããã¡ã€ã«ãŸãã¯ãã£ã¬ã¯ããªã®å Žåã«åé€ããŸãããã£ã¬ã¯ããªãåé€ããå Žåã¯ãã®äžèº«ã¯ç©ºã§ãªããã°ãããŸãããåŸæ¥ã¯ãã£ã¬ã¯ããªã®åé€ã«ã¯ rmdir
ã³ãã³ãã䜿ã£ãŠããŸããã rmdir
ã³ãã³ãã¯ãã£ã¬ã¯ããªããåé€ã§ããªãã®å¯Ÿã㊠rm -d
ã¯ãã¡ã€ã«ãšãã£ã¬ã¯ããªã®äž¡æ¹ãåé€ããããšãã§ãããšããéãããããŸãã
以åãã rm -r
ã§ãã£ã¬ã¯ããªãšãã®äžèº«ã®ååž°çãªåé€ãã§ããŸããããrm -r
ã¯ïŒããã©ã«ãã§ã¯ïŒç°ãªããã¡ã€ã«ã·ã¹ãã ã§ãã£ãŠãåé€ã§ããŠããŸããŸãããããé²ã --one-file-system
㯠GNU ã³ãã³ãã®æ¡åŒµæ©èœã§ããrm -d
㯠find
ã³ãã³ãã® -xdev
è©äŸ¡åŒãšçµã¿åãããŠãããšã§ã--one-file-system
ãšåçã®ããšãè¡ãæ¹æ³ãšããŠããã§ã«å€ãã®å®è£
ã察å¿ããŠããããæšæºåãããŸãããã€ãŸã find
ã³ãã³ãã§ååž°çã«èŠã€ãããã¡ã€ã«ãšãã£ã¬ã¯ããªã®äž¡æ¹ãåé€ããã«ã¯ãrm
ã³ãã³ãã« -d
ãªãã·ã§ã³ãå¿
èŠã§ãããšãã話ã§ãã
$ find . -xdev -depth ! -name . -exec rm -d {} +
-d
ãªãã·ã§ã³ã®è¿œå ãåããŠãç§éã¯èãæ¹ãå°ãå€ããå¿
èŠãããã§ãããããã㯠rm
ã³ãã³ãã¯ãã¡ã€ã«ã·ã¹ãã ãããåé€å
šè¬ãè¡ãã³ãã³ããã«ãªã£ããšããããšã§ãããããŸã§ç§é㯠rm
ã³ãã³ãã¯ãã¡ã€ã«ãåé€ããã³ãã³ãã§ãrmdir
ã¯ãã£ã¬ã¯ããªãåé€ããã³ãã³ãã§ããã¡ã€ã«ããã£ã¬ã¯ããªã§ã³ãã³ãã䜿ãåãããã®ã ãšèããŠããã¯ãã§ãïŒãªã®ã« rm -r
ã§ãã£ã¬ã¯ããªãåé€ã§ãããšããççŸããããŸããããããã解æ¶ãããŸããïŒãrmdir
ã³ãã³ã㯠mkdir
ã³ãã³ããšå¯Ÿãæãã³ãã³ãã§ããã®äºã€ã¯ã空ã®ãã£ã¬ã¯ããªãïŒ-p
ãªãã·ã§ã³ã§ååž°çã«ïŒäœæãŸãã¯åé€ããæã«äœ¿ãã³ãã³ããã§ãããã¡ãããã£ã¬ã¯ããªã®åé€ã« rmdir
ã³ãã³ãã䜿ãã®ã¯éæšå¥šãšèšãã€ããã¯ãããŸãããã·ããããŒãæŒãæéïŒäœããåéãããŠããïŒãã€ãã³ã«æã䌞ã°ãããšãèããã° rmdir
ã³ãã³ãã®ã»ããå
¥åãç°¡åã§ãããã
äœãåé€ãããç¥ããã-vãªãã·ã§ã³ã®è¿œå
äœãåé€ãããç¥ããã -v
ãªãã·ã§ã³ãè¿œå ãããŸããã
sed ã³ãã³ã
sed
ã³ãã³ãã¯ã¹ããªãŒãã³ã°åã®ããã¹ããšãã£ã¿ã§ãããã¹ããšãã£ã¿ã®ã³ãã³ãã䞊ã¹ãã¹ã¯ãªããã䜿ã£ãŠããã¹ããã¹ããªãŒãã³ã°ã§æžãæ¿ããã³ãã³ãã§ãã次ã®ãããªäœ¿ãæ¹ãããŸãã
sed -f ã¹ã¯ãªãã [-f ã¹ã¯ãªãã]... ãã¡ã€ã«...
sed -f myscript file1.txt file2.txt file3.txt
æ¡åŒµæ£èŠè¡šçŸãæå¹ã«ãã -E ãªãã·ã§ã³ã®å¯Ÿå¿
grep
ã³ãã³ããšåãããã«ãsed
ã³ãã³ãã -E
ãªãã·ã§ã³ã§æ¡åŒµæ£èŠè¡šçŸã䜿ããããã«ãªããŸãããéå»ã«ã¯ sed
ã³ãã³ã㯠-r
ãªãã·ã§ã³ã§æ¡åŒµæ£èŠè¡šçŸãæå¹ã«ããŠããŸããããæãã -E
ãªãã·ã§ã³ã«ã察å¿ããŠãããBSD ç³» Unix 㧠-E
ãªãã·ã§ã³ãæ®åããããã« POSIX ã§æšæºåãããŸããã
sã³ãã³ãã«å€§æåå°æåã®åºå¥ãããªãiãã©ã°ã®è¿œå
s
ã³ãã³ãã«å€§æåå°æåã®åºå¥ãããªã i
ãã©ã°ãè¿œå ãããŸãããGNU ã ãã§ã¯ãªããmacOSãFreeBSDãNetBSD ãªã©ã§ããã§ã«å¯Ÿå¿ããŠããŸãã
$ echo Aa | sed 's/a/@/gi'
@@
è£è¶³ã§ããäžéšã®å®è£
ã¯å°æåã® i
ã®ä»£ããã«å€§æå I
ïŒã®ã¿ïŒãåãæå³ã§äœ¿çšããŠããããšã POSIX ã«èšèŒãããŠããŸãã倧æå I
㯠POSIX ã§ã¯æšæºåãããŠããŸããã
å°æ¥ã®æ¹åæ§: æ£èŠè¡šçŸäžã®ããã¯ã¹ã©ãã·ã¥ãšã¹ã±ãŒãæåã®å¯Ÿå¿
çŸåšã® POSIX ã§ã¯æ£èŠè¡šçŸã®äžã«ããã¯ã¹ã©ãã·ã¥ã§ãšã¹ã±ãŒããããæåã䜿ãããšã¯ã§ããŸãããå°æ¥çã«ãã®æ©èœãæšæºåãããããããªãããšãæèšãããŸããã
$ printf "Hello\tWorld\n" | sed 's/\t/:/g'
Hello:World
æ£èŠè¡šçŸäžã®ããã¯ã¹ã©ãã·ã¥ãšã¹ã±ãŒãæåã¯åŸæ¥ã¯ GNU ã³ãã³ãã®ã¿ã察å¿ããŠããŸããããçŸåšã¯ macOS ã FreeBSD ã NetBSD ïŒOpenBSD ã¯çŸæç¹ã§ã¯é察å¿ïŒã§ã察å¿ããããã«åŒ·åãããŠããŸãããã®æµããåããŠå°æ¥ã® POSIX ã¯æšæºåãæ€èšããŠããããã§ãããããŠå°æ¥ãã®åäœãæšæºåãããæã«ããã©ã±ããåŒã®äžã®ããã¯ã¹ã©ãã·ã¥ããšã¹ã±ãŒãã®æå³ã«å€ãããããããªãããããã©ã±ããåŒã®äžã§ã¯2æåã®ããã¯ã¹ã©ãã·ã¥ã䜿çšãã¹ãã§ãããšæèšãããŠããŸãã
# çŸåšã® POSIX ã§ã¯ [ ] ã®äžã¯ \ ãš t ã®æå³ã ã
# GNU ãïŒæè¿ã®ïŒmacOS ã FreeBSD ã NetBSD ã§ã¯ã¿ãã®æå³ã«ãªã
echo 'test' | sed 's/[\t]/@/g' # => @es@ ãŸã㯠test
# POSIX ã¯å°æ¥ã®æ¹åæ§ã®å
容ãããã³çŸåšã®äžéšã®ç°å¢ã®ããã«
# ãã®æžãæ¹ãæšå¥šããŠãããçŸåšã® POSIX ã®åäœã§ã¯2çªç®ã®
# ããã¯ã¹ã©ãã·ã¥ã¯ãã åé·ãªã ããªã®ã§åé¡ã¯çºçããªã
echo 'test' | sed 's/[\\t]/@/g' # => @es@
è£è¶³ã§ãã眮ææååã®äžã® \n
ã«ã€ããŠã¯ POSIX ã¯å°æ¥ã®æ¹åæ§ãå«ããŠäœãèšèŒãããŠããªãããã§ãããçŸåšã®å®è£
ã§ã¯å€ãã®ç°å¢ã \n
ãæ¹è¡ã®æå³ãšããŠäœ¿çšããŸãïŒåæ§ã« \t
ãã¿ããªã©ïŒãããã¯æè¿åºãŸã£ãŠããä»æ§ã§ããã䟿å©ãªæ¡åŒµæ©èœãªã®ã§ãã®åäœãå°æ¥ã® POSIX ã§æšæºåãããå¯èœæ§ãé«ããšæãããŸãã
$ echo "foo:bar" | sed 's/:/\n/g'
foo
bar
å°æ¥ã®æ¹åæ§: åºæ¬æ£èŠè¡šçŸã® \+
ã\?
ã\|
察å¿
sed
ã³ãã³ã以å€ã«ãåœãŠã¯ãŸã POSIX ã§æšæºåãããŠããæ£èŠè¡šçŸå
šè¬ã®è©±ã§ãã
åºæ¬æ£èŠè¡šçŸ (BRE) ãšæ¡åŒµæ£èŠè¡šçŸ (ERE) ã§åãæå³ãšãªãè¡šçŸã察å¿ä»ãããšæ¬¡ã®ããã«ãªããŸãã
BRE ^ $ . [ ] * \{ \} \( \) \ \1...\9
ERE ^ $ . [ ] * + ? { } ( ) | \
POSIX BRE ã«ã¯ +
ãš ?
ãš |
ã«çžåœããæ©èœããããŸãããPOSIX.1-2024 ã§ã¯å°æ¥ãããã«çžåœãã \+
ãš \?
ãš \|
ã®å®è£
ãèŠæ±ãããããããªãããšãæèšãããŸãããå®éãããã㯠GNU ã³ãã³ãã ãã§ã¯ãªã BSD ç³» Unix ã® grep
ã³ãã³ããªã©ã§ãã§ã«å¯Ÿå¿ããŠããåºæ¬æ£èŠè¡šçŸã®æ¡åŒµã¯é²ãã§ããŸãã移æ€æ§ãèªããããã° POSIX ã§æšæºåããããšããã®ã¯éçã§ãããªãæ¡åŒµãé²ãã§ã POSIX æ¡åŒµæ£èŠè¡šçŸã§åŸæ¹åç
§ã®å®è£
ãèŠæ±ãããããšã¯ãªãã§ããããããã¯æ¡åŒµæ£èŠè¡šçŸã§äœ¿çšãããŠããæ£èŠè¡šçŸã®ã¢ã«ãŽãªãºã ã®éœåã§å®è£
ãé£ããããã§ããå°æ¥çã« POSIX æ£èŠè¡šçŸã¯ååã«åããŠåºæ¬æ£èŠè¡šçŸã®ã»ããæ¡åŒµæ£èŠè¡šçŸãããæ©èœãäžã«ãªãæãæ¥ããããããŸããã
è£è¶³ã§ãããæ¡åŒµæ£èŠè¡šçŸã§äœ¿ããªãåŸæ¹åç
§ããšããã®ã¯ sed
ã®çœ®ææååïŒs/æ£èŠè¡šçŸ/眮ææåå/
ïŒã§ã®åç
§ã®ããšã§ã¯ãªããæ£èŠè¡šçŸã®äžã§çšããåŸæ¹åç
§ã®ããšãªã®ã§æ³šæããŠãã ããã眮ææååã§ã®æ£èŠè¡šçŸã«ãããããéšåã®åç
§ã¯æ¡åŒµæ£èŠè¡šçŸã§ãåé¡ãªã䜿ããã®ã§ãsed
ã³ãã³ã㧠-E
ãªãã·ã§ã³ãæå®ãããšããŠãã眮ææååã§ã®åç
§ã POSIX æºæ ããŠããªãããšã«ãªãããã§ã¯ãããŸããã
$ echo abc | sed -E 's/(.)/[\1]/g'
[a][b][c]
sort ã³ãã³ã
sort
ã³ãã³ãã¯ãã¡ã€ã«ã䞊ã¹æ¿ããã³ãã³ãã§ãã
äžæãã¡ã€ã«ã®äœæå Žæãç°å¢å€æ°TMPDIRã§æå®ãã
sort
ã³ãã³ãã¯äžè¬çã«ã¡ã¢ãªã«å
¥ããªããããªå€§ããªãã¡ã€ã«ãããŒãžãœãŒããšåŒã°ããã¢ã«ãŽãªãºã ã䜿çšããŠäžŠã³æ¿ããŸããããŒãžãœãŒãã¯ãã¹ãŠã®ããŒã¿ãã¡ã¢ãªå
ã§äžŠã³æ¿ããã®ã§ã¯ãªãããããµã€ãºããšã®ãœãŒãæžã¿ãã¡ã€ã«ãäœæãããã®ãã¡ã€ã«ãããŒãžïŒäœµåïŒããããšã§å
šäœã䞊ã³æ¿ãããœãŒãæ¹æ³ã§ããã¡ã¢ãªãå€ãæ¶è²»ããªããŠãã¿ãŸãããã®ä»£ããã«äžæãã¡ã€ã«ã䜿çšããŸããã€ãŸããã£ã¹ã¯å®¹éã足ããªããã°ãšã©ãŒã«ãªã£ãŠããŸããŸãããããã£ã¹ã¯å®¹éãèªã¿æžãé床ã®ããã«å¥ã®ãã£ã¬ã¯ããªã䜿çšãããå Žåãç°å¢å€æ° TMPDIR
ã§æå®ããããšãã§ããŸãã
stty ã³ãã³ã
stty
ã³ãã³ãã¯ã¿ãŒããã«ãã©ã€ãã®èšå®ãå€æŽããå
¥åããããŒã«å¯Ÿããåå¿ãå¶åŸ¡ããããã®ã³ãã³ãã§ãã
ã¿ãŒããã«ã®ãŠã€ã³ããŠãµã€ãºã®èšå®ãšååŸ
ã¿ãŒããã«ã®ãŠã€ã³ããŠãµã€ãºã®èšå®ãšååŸãè¡ãããã® rows
ãcols
ãsize
ãè¿œå ãããŸããã
tail ã³ãã³ã
tail
ã³ãã³ãã¯ãã¡ã€ã«ã®æ«å°Ÿãåºåããã³ãã³ãã§ãã
ãã¡ã€ã«ãéé ã«åºåãã-rãªãã·ã§ã³ã®è¿œå
BSD ç³» Unix ã Solaris 11 ãªã©ã§åºãå®è£
ãããŠãããã¡ã€ã«ãéé ã«åºåããããã® -r
ãªãã·ã§ã³ãæšæºåãããŸããããã ãçŸæç¹ã§ã® GNU çã«ã¯å®è£
ãããŠããŸãããGNU çã§ã¯æãããã¡ã€ã«ãéé ã«åºåããããã® tac
ã³ãã³ãã䜿ãããŠããŸããããã¡ã€ã«ãéé ã«åºåããæ©èœã㯠tail
ã³ãã³ãã®ããã¡ã€ã«ã®æ«å°Ÿãé çªã«åºåããæ©èœããšã¯ç°ãªããã Unix å²åŠçã« tail
ã³ãã³ãã« -r
ãªãã·ã§ã³ãå«ããã¹ãã§ã¯ãªããšããèãããã§ããããã POSIX ã«æºæ ããããã«è¿œå ããããšã«ã¯è¯å®çã§ãããããããããè¿ããã¡ã«å®è£
ããããšæãããŸããPOSIX ã§ã¯ tac
ã³ãã³ããš -r
ãªãã·ã§ã³ã®ã©ã¡ããæšæºåãããæ祚ãè¡ã£ãã®ã§ãããä»ã® Unix ã tac
ã³ãã³ãã®å®è£
ããã®ã«æåŸ
ããããããGNU ãªãçŽ æ©ãå®è£
ããŠãããã«éããªããšããèããã -r
ãªãã·ã§ã³ãæ¡çšãããããã§ãã
- https://lists.gnu.org/archive/html/bug-coreutils/2014-10/msg00068.html
- https://www.gnu.org/software/coreutils/manual/html_node/tail-invocation.html
timeout ã³ãã³ãïŒæ°èŠïŒ
timeout
ã³ãã³ã㯠POSIX.1-2024 ã§æ°ããè¿œå ãããã³ãã³ãã§ãã
æéå¶éä»ãã§ã³ãã³ããå®è¡ãã
timeout
ã³ãã³ãã¯æéå¶éä»ãã§ã³ãã³ããå®è¡ããã³ãã³ãã§ãã
$ timeout 3 ping google.com
PING google.com (142.251.42.174) 56(84) bytes of data.
64 bytes from nrt12s46-in-f14.1e100.net (142.251.42.174): icmp_seq=1 ttl=55 time=26.1 ms
64 bytes from nrt12s46-in-f14.1e100.net (142.251.42.174): icmp_seq=2 ttl=55 time=23.1 ms
64 bytes from nrt12s46-in-f14.1e100.net (142.251.42.174): icmp_seq=3 ttl=55 time=23.3 ms
timeout
ã³ãã³ãã䟿å©ãªã³ãã³ãã§ã·ã§ã«ã¹ã¯ãªããã§å®è£
ããã®ãé£ãããšããã®ã¯ãããã®ã§ããã£ãã»ããè¯ããšããã®ã¯ãã®ãšãããªã®ã§ããã察話çãªçšéã§äœ¿ãããã°ã©ã ã§äœ¿ããã®ãšããæããã·ã§ã«ã¹ã¯ãªããã«ãšã£ãŠåœ¹ã«ç«ã€ãã®ã§ã¯ãªãã®ã§ãPOSIX ã®æ¹éçã«æšæºåããå¿
èŠããã£ãã®ãçåã§ããè°è«ãã»ãšãã©ãªãæšæºåãããŠããŸãã
å€ãã®äººã¯ã¿ã€ã ã¢ãŠãä»ãå
¥åã«äœ¿ãããã®ã§ã¯ãªãããªãšæãã®ã§ãµã³ãã«ã³ãŒãã§ããread
ã³ãã³ãã§ã¯ãªã head -n 1
ã§äžè¡ã®å
¥åãè¡ã£ãŠããã®ã¯ read
ã³ãã³ããã·ã§ã«ãã«ãã€ã³ã³ãã³ããªã®ã§ timeout
ã³ãã³ãããåŒã³åºãããšãã§ããªãããã§ãã
$ input=$(timeout -f 3 head -n 1)
ãçŸæç¹ã§ã¯ GNU ç㯠-f ãªãã·ã§ã³ã«é察å¿ãªã®ã§ --foregroud ã䜿ãã
$ input=$(timeout --foreground 3 head -n 1)
äœè«ã§ãããSystem V ç³» Unix ã§ã¯äžè¡ãèªã¿èŸŒãã§äžè¡ãåºåããããã® line
ã³ãã³ããæã£ãŠãŸããããã POSIX ã§ã¯ line
ã³ãã³ããæšæºåãã代ããã« read
ã³ãã³ãã«è¡ããã®ãŸãŸïŒããã¯ã¹ã©ãã·ã¥ã解éããã«ïŒèªã¿èŸŒãããã® -r
ãªãã·ã§ã³ãè¿œå ãããšããçµç·¯ããããŸããread
ã³ãã³ãã§è¡ããã®ãŸãŸèªã¿èŸŒããšãã¯ãã¡ãã¡ãš IFS= read -r
ãšæžããªããã°ãããªããŠé¢åãªã®ã§ãããå
ã
read
ã³ãã³ãã¯åçŽãªè¡ãèªã¿èŸŒãããã®ã³ãã³ãã§ã¯ãªãïŒããçš®ã®ãã©ãŒããããæã£ãïŒããŒã¿ãèªã¿èŸŒãããã®ã³ãã³ããšããããšãªã®ã§ãããã
uuencode / uudecode ã³ãã³ã
uuencode
ã³ãã³ããš uudecode
ã³ãã³ãã¯ãã®åã®éã uuencode ãšåŒã°ãããšã³ã³ãŒãã£ã³ã°ã«ãããŒã¿ããšã³ã³ãŒããè¡ãã³ãã³ããšãã³ãŒããè¡ãã³ãã³ãã§ããæ¬æ¥ã¯ã
base64 ãšã³ã³ãŒããè¡ã -m ãªãã·ã§ã³ã®è¿œå
base64 ãšã³ã³ãŒãã£ã³ã°ã¯ uuencode ãšã¯å¥ã®ãšã³ã³ãŒãã£ã³ã°ã§ãããã©ã¡ããã¡ãŒã«ã«ãã€ããªãã¡ã€ã«ãåã蟌ããšããçšéã§äœ¿ãããŠãããšããç¹ã§å
±éç¹ããããŸããuuencode ãšããååããã¯åããŠããŸãããçŸåšã®ã»ãšãã©ïŒãã¹ãŠïŒïŒã®å®è£
ã -m
ãªãã·ã§ã³ã§ base64 ãšã³ã³ãŒãã»ãã³ãŒããè¡ãæ©èœãæã£ãŠãããšããçŸå®ããããã®æ©èœã POSIX ã§æšæºåãããŸããã
$ echo test | uuencode -
begin 664 -
%=&5S=`H`
`
end
$ echo test | uuencode -m -
begin-base64 664 -
dGVzdAo=
====
å€æããŒã¿ãèŠããšãããããã«ïŒã¡ãŒã«ã«åã蟌ãæã«å¿
èŠãªïŒããããä»ããŠãããããéåžžã® base64 ãšã³ã³ãŒãã£ã³ã°ãšã¯ç°ãªããŸãããã ãæåãšæåŸã®è¡ãåãé€ãã°éåžžã® base64 ãšã³ã³ãŒãã£ã³ã°ãšããŠäœ¿çšå¯èœã§ãããã㯠sed
ã³ãã³ããªã©ãçšããŠç°¡åã«è¡ãããšãã§ããŸãã
$ echo test | uuencode -m - | sed '1d;$d'
dGVzdAo=
ïŒPOSIX ã§æšæºåãããŠããªã base64 ã³ãã³ããšåãçµæïŒ
$ echo test | base64
dGVzdAo=
åé¿ç: POSIXã³ãã³ãã®ã¿ã䜿ã£ãbase64ã®å®è£
ããããçžåœå€ãç°å¢ã§ãªãéãã-m
ãªãã·ã§ã³ã¯å®è£
ãããŠããããã§ããSolaris ã AIX ã«ãå®è£
ãããŠããŸããç¹ã«äœ¿ãçç±ã¯ãªããããªæ°ãããŸãããPOSIXã³ãã³ãã®ã¿ïŒã〠uuencode
/ uudecode
ã® -m ãªãã·ã§ã³ã䜿çšããªãã§ïŒbase64 ãå®è£
ããŠããã®ã§èå³ãããæ¹ã¯åç
§ããŠã¿ãŠãã ããã
xargs ã³ãã³ã
xargs
ã³ãã³ãã¯ãå€ãããåŒæ°ãåå²ããŠè€æ°åã®ã³ãã³ãåŒã³åºãã«åããŠåŒã³åºãããã®ã³ãã³ããã§ããè£è¶³ã§ãããxargs
ã³ãã³ãã®ä»æ§ã¯è€éã§åé¡ãèµ·ããããã®ã§ãå
¥åããã¡ã€ã«åã®å Žå㯠xargs
ãšçµã¿åãããããšã¯ãããå¯èœãªéã find ... -exec {} +
ã䜿çšããããã«ããŠãã ããã
ãæšå¥š: ãã¡ã€ã«åãå®å
šã«æ±ãããšã§ãéãã
$ find . -name "*.txt" -exec touch {} +
ãæšå¥šããªã: äžèšãšåçã®æ¹æ³ïŒå®å
šã«æ±ãããšãããšåé·ã«ãªãïŒã
$ find . -name "*.txt" -print0 | xargs -0 -r touch
-0 ãªãã·ã§ã³ã®è¿œå
xargs
ã³ãã³ãã® -0
ãªãã·ã§ã³ã¯ find
ã³ãã³ãã® -print0
ãªã©ã§åºåãããã«æåçµç«¯æååãèªã¿åãããã®ãªãã·ã§ã³ã§ããããã¯ã¹ããŒã¹ãæ¹è¡ãå«ãŸããŠããæååãé©åã«æ±ãããã®ãã®ã§ãããã«æååºåãã§ã¯ãªãã®ã§æ³šæããŠãã ãããã€ãŸãããã¹ããã¡ã€ã«ã®æåŸã®è¡ã«æ¹è¡ãå¿
èŠãªããã«æåŸã«ãã«æåãå¿
èŠã§ãã
ãæ£ããïŒãã«æåã¯çµç«¯æåïŒã
foo<NUL>bar<NUL>baz<NUL>
ãééãïŒãã«æåã¯åºåãæåã§ã¯ãªãïŒã
foo<NUL>bar<NUL>baz
POSIX ã§ã¯æ«å°Ÿã®ãã«æå以å€ïŒã€ãŸãäžèšã®ééãã®æ«å°Ÿã®ãbazãïŒã¯ç¡èŠããããšãæšå¥šãããŠããŸããéä¿¡åæãªã©ã§ãéåããå£ããããŒã¿ãã®å¯èœæ§ãããããã§ãããã ãçŸåšã®å®è£ ã¯ïŒãããããã¹ãŠïŒæ«å°Ÿã®ãã«æå以å€ãç¡èŠããŸããããç¡èŠããªããŠãè¯ãããšã«ãªã£ãŠããŸãã
If the standard input is not empty and does not end with a null byte, xargs should ignore the trailing non-null bytes (as this can signal incomplete data) but may use them as the last argument passed to utility.
POSIX ã§ãæåã¯æ«å°Ÿã®ãã«æå以å€ãç¡èŠããªããšããå 容ã ã£ãã®ã§ãããäžå®å šãªããŒã¿ã®å¯èœæ§ããããšããŠç°è°ç³ãç«ãŠãè¡ãããããæ¡çšãããŸãããããã¹ãããŒã¿ã®æçµè¡ã«æ¹è¡ããªãå Žåãæçµè¡ãç¡èŠãããããšããããŸãããããããã«æåçµç«¯ã®å Žåã«ãçºçããå¯èœæ§ãèãããããšããããšã§ãã
ãã«æåãé£ç¶ããŠããå Žåããããããåå¥ã®åºåãæåãšããŠæ±ãããŸããããã POSIX.1-2024 ã§æå®ãããåäœã§ãããGNU çãSolaris 11çãOpenBSD çã§ã¯ãã®ãšããã«åäœããŸãããããïŒçŸæç¹ã®ïŒFreeBSD çãš NetBSD çãšm acOS çã¯ç¡èŠãããã®ã§æ³šæããŠãã ãããå€æŽãããšäºææ§ãä¿ãŠãªãããå°æ¥ POSIX.1-2024 ã«æºæ ããä»æ§å€æŽã¯è¡ãããªãã®ã§ã¯ãªãããšèããŠããŸãã
$ printf 'foo\0bar\0\0baz\0' | xargs -0 -n 1
foo
bar
baz
$ printf 'foo\0bar\0\0baz\0' | xargs -0 -n 1
foo
bar
baz
åŒæ°ããªããšãã«ã³ãã³ãåŒã³åºããªã-rãªãã·ã§ã³ã®è¿œå
GNU çãš System V 系㮠xargs
ã³ãã³ãã¯åŒæ°ããªããŠãã³ãã³ããåŒã³åºããŸããããã BSD 系㮠xargs
ã³ãã³ãã¯åŒæ°ããªãæã«ã³ãã³ããåŒã³åºããŸããã
$ cat /dev/null | xargs printf "[%s]\n"
[]
$ cat /dev/null | xargs printf "[%s]\n"
äŒçµ±ç㪠xargs
ã³ãã³ãã®ä»æ§ã¯ãåŒæ°ããªããŠãã³ãã³ããåŒã³åºããã»ãã§ãããã㯠xargs
ã®æ¬æ¥ã®æ©èœããå€ãããåŒæ°ãåå²ããŠè€æ°åã®ã³ãã³ãåŒã³åºãã«åããŠåŒã³åºãããã®ã³ãã³ããã§ããããšããç解ã§ããåäœã§ããã€ãŸã touch
ã³ãã³ãã®åŒæ°ããªããŠã touch
ã³ãã³ãã¯å®è¡ã§ããŸãããïŒãšããããšã§ãã
æ°ããæšæºåããã -r
ãªãã·ã§ã³ã䜿çšãããšãBSD ç³»ã®ããã«ã³ãã³ããåŒã³åºããªããªããŸããBSD ç³»ã§ã¯ -r
ãªãã·ã§ã³ã¯äœãããªããªãã·ã§ã³ãšããŠå®è£
ãããŠããŸãã
$ cat /dev/null | xargs -r printf "[%s]\n"
ã¡ãªã¿ã« POSIX.1-2024 ã§ã¯ -r
ãªãã·ã§ã³ãæå®ãããŠããªããšãã¯ã¡ããã©äžååŒã³åºããããšèŠå®ãããŠããã®ã§ãçŸåšã® BSD ç³»ã®å®è£
㯠POSIX.1-2024 ã«æºæ ããŠããªãããšã«ãªããšæãããŸãã
å°æ¥ã®æ¹åæ§: ãã¡ã€ã«åã«æ¹è¡æåã䜿ããªãããã«ãã
ãã¡ã€ã«åãæ±ãããã€ãã®ã³ãã³ãã«å¯ŸããŠã次ã®ãããªæç« ã«è©²åœããå®è£ ãè¡ãããã«å¥šå±ãããŸãããã€ãŸããã¡ã€ã«åã®äžéšã«æ¹è¡æåãå«ããããšãã§ããªãããã«ããããšããæµãã§ãããã¡ã€ã«åã«å«ãŸããæ¹è¡æåã¯ãã¡ã€ã«åããã€ãã§å¥ã®ã³ãã³ãã«æž¡ãããšãã«åé¡ãçºçããå Žåã«ãã£ãŠã¯è匱æ§ãå«ãé倧ãªåé¡ã«çºå±ããŠããŸãå¯èœæ§ããããŸãã
Austin Group Defect 251 is applied, encouraging implementations to disallow the creation of filenames containing any bytes that have the encoded value of a
<newline>
character.
èš³ Austin Group Defect 251 ãé©çšããã<newline>
æåã®ãšã³ã³ãŒãå€ãæã€ãã€ããå«ããã¡ã€ã«åã®äœæãçŠæ¢ãããããªå®è£
ã奚å±ããã
Austin Group Defect 251 is applied, encouraging implementations to report an error if a utility is directed to display a pathname that contains any bytes that have the encoded value of a
<newline>
character when<newline>
is a terminator or separator in the output format being used.
èš³ Austin Group Defect 251 ãé©çšããããã䜿çšãããŠããåºåãã©ãŒããã㧠<newline>
ãã¿ãŒãããŒã¿ãŒãŸãã¯ã»ãã¬ãŒã¿ãŒã§ããå Žåã«ã<newline>
æåã®ãšã³ã³ãŒãå€ãæã€ãã€ããå«ããã¹åã衚瀺ããããã«ãŠãŒãã£ãªãã£ãæ瀺ãããå Žåããšã©ãŒãå ±åãããããªå®è£
ã奚å±ããã
ãå®è£ ã奚å±ãã (encouraging implementations)ããšåŒ·å¶åããªããããªæç« ã«ãªã£ãŠããã®ã¯ãPOSIX ããã®ãããªå®è£ ã匷ãèŠæ±ããŠããããã§ã¯ãªããšããæå³ã®è¡šãã§ãå®è£ ãããã©ããã¯å®è£ è ã決ããããšã§ãPOSIX ã®ç«å ŽãšããŠã¯æ¢åã®æ £è¡ã§ã¯ãªãæ°ããæ©èœã«å¯ŸããŠææ¡ããã§ããªãããã§ãã
Austin Group Defect 251 ãšã¯ 0000251: Forbid newline, or even bytes 1 through 31 (inclusive), in filenames ã®ããšã§ããå ã ã®ææ¡ã¯æ¹è¡æåãå«ãå¶åŸ¡æåãŸã§èæ ®ãããŠããŸããããé·ãè°è«ãçµãŠç¹ã«åé¡ã倧ããæ¹è¡ã®ã¿ã®çŠæ¢ãšãªããŸãããçŸå®ã®å®è£ ãããã«åŸããã©ããã¯ãŸã æªç¥æ°ã§ãããå人çã«ã¯å®çŸããŠæ¬²ããã§ããã誰ãæ¹è¡æåããã¡ã€ã«åã«å«ãããããªããšã¯ããŸãããåé¡ãèµ·ãããšã¯æããŸãããã©ã® Unix/Linux ãä»ãŸã§ãã£ãŠããªãã£ããšããã ãã§ãããããŠä»ãŸã§èª°ããã£ãŠããªãã£ãã®ã§ POSIX ã§æšæºåããããšãã§ããŸããã§ããã
å°æ¥ã®POSIXã§è¿œå ããããããããªãæ©èœ
POSIX ã®æ¹å®ã¯ POSIX.1-2024 ã§çµãã£ãããã§ã¯ãããŸããã次ã®æ¹å®ã§ãã Issue 9 ãžã®æ¹å®äœæ¥ã¯ãã§ã«å§ãŸã£ãŠããŸããããããæ¹å®ãè¡ãããã®ã¯ãããŸã§ã®ããŒã¹ãã 10 幎åŸãããã«ãªãã§ããããããã§ã¯ç§ãè¿œå ãããå¯èœæ§ãé«ããšæã£ãæ©èœãããã€ãã玹ä»ããŸãããçŸæç¹ã§ã®æ å ±ã§ããå ¬éããããŸã§ã«å 容ãå€ãã£ããå Žåã«ãã£ãŠã¯æåŠããããããããªãã®ã§æ³šæããŠãã ããããã£ãšã POSIX ã¯çŸåšã®å®è£ ãææåãããã®ã§ãããããçŸåšãšäºææ§ããªãä»æ§ã«å€ãã£ãŠããŸãããšã¯ãŸããããŸããã
xargs ã³ãã³ã
䞊åå®è¡ã®ããã®-Pãªãã·ã§ã³ã®è¿œå
xargs ã³ãã³ãã« -PïŒäžŠåå®è¡ïŒãªãã·ã§ã³ã®è¿œå ãææ¡ãããŸããããããŠãã§ã«ãã®ææ¡ã¯åãå ¥ããããŠããŸããé©ãã¹ãããšã«ããã®æ©èœã¯ããã2ã«æïŒäžåºŠåãå ¥ããããã®ã¯1ã¶æçšåºŠïŒã§æšæºåãããŸãããããææ¡ãæ©ããã° POSIX.1-2024 ã«éã«åã£ãŠããå¯èœæ§ãé«ãã§ããã¡ãã£ãšæ®å¿µã§ããæšæºåãããŠããªããšããã ãã§äœ¿ãããšæãã°äœ¿ããããã§å¥ã«æ¯éã¯ãããŸããã
ãã®å 容㯠POSIX.1-2024 ã® TC1ïŒTechnical Corrigendum 1: æè¡èšæ£äºé 1ïŒãšããŠïŒããããäœå¹ŽåŸãã®ïŒå°èŠæš¡ãªæ¹å®ã§ãå°æ¥ã®æ¹åæ§ãã«è¿œèšãããäºå®ã§ãã
- 0001801: xargs: add -P option
- 0001811: xargs: add -P option to FUTURE DIRECTIONS section
- 0001812: Support xargs -P 0
äœè«: ãPOSIXã«ãã£ãŠèœåãå¶éãããŠããããšãããæå³äžæãªè©±
äœè«ã§ããããã®è©±ã§æãåºãã®ã¯ä»¥äžã®èšäºã§ãã
ã³ã¢ãå€æ°æèŒããCPUã¯ãPOSIXãã«ãã£ãŠèœåãå¶éãããŠãããšã®ææ
ãã®èšäºã§ã¯æ¬¡ã®ããã« POSIX ããã«ãã³ã¢CPUã®èœåãå¶éããèŠå ãšãªã£ãŠãããšæžãããŠããŸããããããªããšã¯ãããŸãããPOSIX ã¯æ¡åŒµæ©èœã®å®è£ ãçŠæ¢ããŠããªãããã§ããïŒè£è¶³: ãPOSIX ããã«ãã³ã¢CPUã®èœåãå¶éããèŠå ãšãªã£ãŠããããšæžããŠããã®ã¯ Gigazine ã§ãããå èšäºã«ã¯ãã®ããã«æžããŠãªãããã«ãèªããŸãããPOSIX.2 ãå¶éãšæããŠãããããªã®ã§ Gigazine ã®è§£éãããªãã¡ééã£ããã®ã§ã¯ãªãã§ããããïŒ
ã·ã¹ãã 管çè ã®ãã£ãŒã«ãºã»ãã£ãã·ã£ãŒæ°ã¯ãPOSIXããã«ãã³ã¢CPUã®èœåãå¶éããèŠå ãšãªã£ãŠããããšææãããxargsãã³ãã³ããäŸãšããŠå ·äœçãªèª¬æãè¡ã£ãŠããŸãã
ïŒäžç¥ïŒ
POSIXã«ãã£ãŠäžŠååŠçã®å¶éãåããããšã¯ãçŸä»£ã«ãããŠç°è³ªããªããšã ãšãã£ãã·ã£ãŒæ°ã¯ææã
POSIX ã¯ïŒã·ã§ã«ã¹ã¯ãªãããå«ãïŒã¢ããªã±ãŒã·ã§ã³éçºè
ã«å¯ŸããŠãã©ã®æ©èœã移æ€æ§ãããããæ確ã«ããŠããã ãã§ããPOSIX 㯠OS ãã³ãã³ãã®å®è£
è
ã«å¯ŸããŠãäœããããŠã¯ãããªããšããå¶éãã§ã¯ãªãïŒæ°ãã OS ãã³ãã³ããå®è£
ãã人ã«ãšã£ãŠã®ïŒæäœæ¡ä»¶ã§ããå®è£
è
㯠POSIX ãè¶
ããæ¡åŒµæ©èœãèªç±ã«å®è£
ããããšãã§ãã移æ€æ§ãé«ããšèªããã° POSIX ã¯ãã®æ©èœãæšæºåããŸãããã®èšŒæ ã« -P
ãªãã·ã§ã³ã¯å€ãã®ç°å¢ã§å®è£
ããããã POSIX ã§æšæºåãããŸãããPOSIX ã§æšæºåããŠããªãã£ãããšã«å¯ŸããŠã®æå¥ãèšãã®ã§ããã°ããã®æå¥ãèšãå
㯠POSIX ã§ã¯ãªã -P
ãªãã·ã§ã³ãå®è£
ããŠããªã ïŒç¹ã«åçšã®ïŒUnix éçºè
ã§ãããã® Unix ããªãŒãã³ãœãŒã¹ã§ããã°èª°ã§ã -P
ãªãã·ã§ã³ãå®è£
ããŠæã¡èŸŒãããšãã§ããŸãããã㊠POSIX æšæºèŠæ Œã ã£ãŠèª°ã§ãææ¡ã§ããããã§ããããPOSIX ã«æå¥ãèšãããããªãèªåãæšæºèŠæ Œãæžã㊠POSIX ã«ææ¡ãããšãã話ã§ããæ®å¿µãªãã -P
ã®æšæºå㯠10 幎åŸã«æã¡è¶ãããŸãããããã®èšäºã®äž»åŒµã¯çå€ãã§æ代é
ãã®ãã®ãšãªããŸãããå
èšäºã§èšåãããŠããã-0
ã®ãªã xargs
ã㯠POSIX.1-2024 ããèŠããšããéå»ã®è©±ã§ãã
å èšäºã§ã¯çŸåšã¯ååšããªããPOSIX.2 ã§ã¯å€ãã®ããŒã«ã 1970 幎代ã®ãŸãŸã«ããŠããå¿ èŠãããããšæžããŠããŸããããã®ãããªããšããããªã㊠POSIX ã¯èšã£ãŠãããã1970 幎代ã®ãŸãŸã ãšãããããã㯠Unix éçºè ã®æ æ ¢ã§ãããããã POSIX 㯠1988 幎ã«çå®ãããã®ã§ 1970 幎代ãšããã®ãããããªè©±ã§ãããPOSIX 㯠Unix éçºè ã«å®è£ ãããšãå®è£ ãããªãšãåœä»€ãåºãããšã¯ãããŸãããæšæºèŠæ Œããã£ããšããŠããããã«æºæ ãããã©ãã㯠Unix éçºè ã決ããããšã§ããæŽã«èšããªãã° ãPOSIX.2ããšããååã®æšæºèŠæ Œã¯ãã§ã«ãããŸããããŸããPOSIX ã¯å€ãã®åéã§çµ¶å¯ŸçãªæšæºãšèŠãªãããŠããŸããããšæžããŠãããŸããã誰ã絶察çãªæšæºãšã¯ã¿ãªããŠããŸãããSELinux ãš systemd ã POSIX ããããã«äžåã£ããšãããŸããããããã SELinux ã systemd ã®åé㯠OS äŸåã§åœããåã®é åã§ãããã¢ããªã±ãŒã·ã§ã³ã移æ€ããäžã§ãªãã®é¢ä¿ããªãã®ã§ POSIX ã®æšæºåã®å¯Ÿè±¡ç¯å²ã§ã¯ãããŸãããPOSIX ã¯æ¡åŒµæ©èœã®å®è£ ãèš±å¯ããŠãããæ¡åŒµæ©èœã POSIX ã§æšæºåãããã®ã¯æ¡åŒµæ©èœãæ®åããŠããã§ããGNU xargs ã®æ¡åŒµæ©èœã¯ãPOSIX.2 ã«æºæ ããŠããªãããšããè¡šçŸã¯é©åã§ã¯ãªããåã«ãPOSIX.2 ã§æšæºåãããŠããªãïŒPOSIX ãèªç±ã«å®è£ ãèš±å¯ããŠããïŒæ¡åŒµæ©èœããšããã ãã§ããããããåçš UNIX ã§ãã£ãŠã GNU xargs ãã€ã³ã¹ããŒã«ããŠäœ¿ãããšã¯ã§ããããã§ããã«ãã³ã¢ CPU ã®èœåãå¶éããèŠå ãšãªã£ãŠãããã®ã¯ãOS ã«æšæºã€ã³ã¹ããŒã«ãããŠããã³ãã³ããã䜿ããªããããšãã銬鹿ããèãæ¹ã§ããGigazine ãæžããŠããå 容ã¯å èšäºãããããã«æå³äžæãªãã®ãšãªã£ãŠããŸãããå èšäºã®å 容ã POSIX ãç解ããŠãããšã¯èšããŸããã
mktemp ã³ãã³ãïŒæ°èŠïŒ
äžæãã¡ã€ã«ããã£ã¬ã¯ããªãäœæãã mktemp ã³ãã³ãã®è¿œå
mktemp
ã³ãã³ãã¯äžæãã¡ã€ã«ãäžæãã£ã¬ã¯ããªãã»ãã¥ãªãã£çã«å®å
šãªæ¹æ³ã§äœæããããã®ã³ãã³ãã§ããç¹ã«å察æèŠãããããã§ã¯ãªãã®ã§ãããææ¡ãããææãé
ãä¿çç¶æ
ã«ãªã£ãŠããŸããmktemp
ã³ãã³ãã¯å€ãã®ç°å¢ã§å®è£
ãããŠããç°¡åãªäœ¿ãæ¹ã§ããã°ç§»æ€æ§ããããããç§ã¯ãã®ææ¡ã¯åãå
¥ããããã ãããšèããŠããŸãã
äœè«ã§ãããmktemp
ã³ãã³ã㯠POSIX ã«ããæšæºåã®åæã«ææ¡ãããŠããã®ã§ãããæšæºåãããªãã£ãã®ã¯ã·ã§ã«ã«è¿œå ããã set -C
(noclobber) ãªãã·ã§ã³ã«ãã£ãŠçœ®ãæããããšãå¯èœã§ãããããšããã®ãçç±ã§ãããããä»åã®ææ¡ã§ã説æãããŠããéããã·ã§ã«ã¹ã¯ãªãã㧠mktemp
ã³ãã³ãçžåœã®ãã®ãæ£ããäœãã®ã¯å€§å€ã§ãã
åé¿ç: å®å šã«äžæãã¡ã€ã«ãäœæããã·ã§ã«é¢æ°ã®å®è£
ãã mktemp
ã³ãã³ããå
¥ã£ãŠããªãç°å¢ãããã㯠POSIX ã³ãã³ã以å€ã䜿çšããããªãå Žåã¯ããã®ä»£ãããšãªã maketemp
ã·ã§ã«é¢æ°ãäœæããŠããã®ã§ãã¡ãã䜿çšããŠãã ãããã»ãã¥ãªãã£çã«å®å
šãªå®è£
ã«ãªã£ãŠãããããã«äžæ FIFO ãã¡ã€ã«ã®äœæã«ã察å¿ããŠããŸããä»ã«ã m4
ã³ãã³ãã䜿çšããäžæãã¡ã€ã«ã®äœææ¹æ³ãããããã§ããæªæ€èšŒã§ãã
awk ã³ãã³ã
FSã空æåã®å Žåã«äžæååäœã§åºåã
awk
ã³ãã³ã㧠FS
ã空æåã®æã«äžæååäœã§åºåããšããæ©èœã®æšæºåãææ¡ãããŸããããã®æ©èœã¯ææ°ã® gawk
ãmawk
ãnawk
ãbusybox awk
ãgoawk
ã§å®è£
ãã¿ã§ãç¹ã«è°è«ããå
容ããªãã£ãã®ããææ¡ã¯ãã§ã«ãã£ãããšåãå
¥ããããŠããŸãã
$ echo test | awk -F '' '{print $1 " " $2 " " $3 " " $4 }'
t e s t
printf ã³ãã³ã
æ°å€ã3æ¡åºåãã«ããæžåŒã®è¿œå
printf
ã³ãã³ãã«æ°å€ãã«ã³ãã§3æ¡ããšã«åºåãæ©èœãããæ£ç¢ºã«ã¯ãã±ãŒã«äŸåã®æ¡åºåãæåïŒåºåãæåã¯ã«ã³ããšã¯éããŸããïŒã䜿ã£ãŠããã±ãŒã«äŸåã®æ¡æ°ããšïŒæ¡æ°ã¯3æ¡ãšã¯éããŸããïŒã«åºåãæ©èœã®æšæºåãææ¡ãããŸããã
$ printf "%'d\n" 10000
10,000
ãã®ææ¡ã®è°è«ã¯é²ãã§ããŸããããããšããšå¥ä»¶ã®é»è©±äŒè°ã§è©±é¡ã«ãªã£ãŠããããã§ã«åºãå®è£ ãããŠããã POSIX.1-2024 ã«å«ããã«ã¯é ããããšããçç±ã§æ¡çšãããªãã£ããã®ã§ãã話é¡ã«ãªã£ãããã§ã®ææ¡ãªã®ã§ãããããæ¡çšãããã®ã§ã¯ãªãããšèããããŸãã
getconf ã³ãã³ã
ãã¹ãŠã®èšå®å€ãåºåãã-aãªãã·ã§ã³ã®è¿œå
getconf
ã³ãã³ãã«ãã¹ãŠã®èšå®å€ãåºåãã -a
ãªãã·ã§ã³ã®è¿œå ãææ¡ãããŸããã-a
ãªãã·ã§ã³ã¯ãã§ã«å€ãã®ç°å¢ã§å®è£
ãããŠããããã§ã«ææ¡ã¯åãå
¥ããããŠããŸãããã ãçŸæç¹ã¯ãŸã 詳现ã«é¢ããŠã®è°è«ãç¶ããŠãããããæçµçã«åãå
¥ããããå¯èœæ§ãé«ãã§ããäœãããã®å€æŽãå
¥ãå¯èœæ§ããããŸãã
ãããã«
ä»åã®æ¹å®ã¯ïŒæšæºèŠæ Œã®æéåããé²ãããã® POSIX.1-2017 ãé€ããŠïŒ2008 幎ãã 16 幎ã¶ããšãããé·ãæéãããã£ãæ¹å®ãšãªããŸãããããŸãã«ãé·ãã£ããããPOSIX ã¯æ代é ãã«ãªã£ãæšæºèŠæ Œã ãšãå€§å¹ ãªæ¹å®ããªãæšæºèŠæ Œã ãšæãããŠããããããããã§ããããããªäºã¯ãããŸãããä»åã¯å°ãé·ãæ¹å®ãããŠããªãã£ããšèšãã ãã§ããé»è©±äŒè°ã¯ïŒç¹å¥ãªå Žåãé€ããŠïŒæ¯é±äºåè¡ãããŠãããæ¹å®äœæ¥ã¯ä»ãç¶ç¶ããŠè¡ãããŠããŸãããããŠã·ã§ã«ã«ãã³ãã³ãã«ãæ°ããæ©èœã¯è¿œå ãã䟿å©ã«æ¹è¯ãããŠã€ã¥ããŠããŸããããã§ããPOSIX ãæ¹å®ãããã·ã§ã«ã¹ã¯ãªããã®äžçãå€ããã®ã§ããã·ã§ã«ã¹ã¯ãªãããå€ãããªããšæã£ãŠããïŒèšã£ãŠããïŒäººã¯ãåã«ã·ã§ã«ã¹ã¯ãªããã®æžãæ¹ãå€ãã£ãŠããããšãç¥ããªãã£ãããå€ãæžãæ¹ã«åºå·ããŠæ°ããæžãæ¹ã«å€ããããšããŠããªãã ããªã®ã§ãã
POSIX æšæºèŠæ Œã«é¢ããã¡ã³ããŒïŒã€ãŸãã¡ãŒãªã³ã°ãªã¹ãã«ç»é²ããŠçºèšãã人ã ïŒã¯æšæºèŠæ Œã®ãã°ã®ææãæ°ããææ¡ãããæ©èœã«å¯ŸããŠãã·ã§ã«ãã³ãã³ãã«é¢ããåäœã«ã€ããŠèª¿ã¹ããè°è«ãéããªããæšæºèŠæ Œãæ¹å®ããŠããŸããæšæºèŠæ Œãèªãã®ã¯å€§å€ã§ãããããã«ã¯çŸå®ã®ã·ã§ã«ãã³ãã³ãã®åé¡ã詳现ã«æ£ç¢ºã«æžãããŠããŸãããã®ããã«ããŠçå®ããã POSIX æšæºèŠæ Œã泚ææ·±ãèªãã§å¯Ÿå¿ããã°ç§»æ€æ§ãé«ãã·ã§ã«ã¹ã¯ãªãããæžãããšãã§ããŸããã©ã®ç°å¢ã«ã§ãããã«ãšèšãããã«ã¯ãããªããããããŸããããæ°ããæ©èœã䜿ããšãããŸã§ã§ããªãã£ãããšãäžäŸ¿ã ã£ãããšã解æ¶ãããŸããå€ãã·ã§ã«ãã³ãã³ããå€ã POSIX æšæºèŠæ Œã®å¶éããããåé¿çãæšãŠãç¥èãã¢ããããŒãããŠæ°ããæžãæ¹ãžãšå€ããŠãããŸããããããããããšãç°¡åã«ã§ããªããã°ã·ã§ã«ã¹ã¯ãªããã§æžãæå³ã¯ãããŸããã