Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?
ã§ããã°ã·ã§ã«ã¹ã¯ãªãããªãã¦æ¸ããããªããã ãã©ï¼ã¾ã ã¾ã æ¸ãæ©ä¼ã¯å¤ãï¼ã·ã§ã«è¸ãã¯ã³ã©ã¤ãã¼ã®ãããªåã£ããã¨ã§ã¯ãªãï¼ä»ã®ã²ã¨ã使ããããã·ã§ã«ã¹ã¯ãªãããæ¸ãããã«èªåãå®è·µãã¦ãããã¨ãã¾ã¨ãã¦ããï¼ ãã«ãã¡ãã»ã¼ã¸ æ¸ãã¦ãã·ã§ã«ã¹ã¯ãªããã使ãæ¨ã¦ã§ã¯ãªãä½åº¦ã使ããã®ã§ããå ´åã¯ï¼æ¬ä½ãæ¸ãå§ããåã«ï¼ãã®ã¹ã¯ãªããã®ä½¿ãæ¹ã表示ããusageé¢æ°ãæ¸ãã¦ãã¾ãï¼ ãããæ¸ãã¦ããã¨ï¼å¾ã ãã¼ã ã¸å ±æããããããªãï¼ã¨ããããusageè¦ã¦ãã ããã¨è¨ããï¼ã¾ãï¼ãããããæ¸ããã¨ã§ï¼åãªãã·ã§ã«ã¹ã¯ãªããã§ãã£ã¦ãèªåã®ä¸ã§åä½ãæ´çãã¦ããæ¸ãå§ãããã¨ãã§ããï¼é¢æ°ã¨ãã¦æ¸ãã®ã¯ï¼usageã表示ãã¦ãããã¨ããå ´é¢ãããã¤ãããï¼ä½¿ãåããã¨ãã§ããããï¼ ä»¥ä¸ã®ããã«æ¸ãï¼ function usage { cat <<EOF $(basename ${0})
shell script ã¯æ®æ®µããã¦éãããã¨é¡ã£ã¦ãã¾ãªãããã§ããããã¾ã«ã¯æ¸ããªãã¨ãããªããã¨ãããã®ã§ãããããã¨ãã¯è¦ãã¦ããã¨ä¾¿å©ãª tips ã2ã¤ã autodie ã£ã½ãããset -eã¨ããã¨ãã³ãã³ãã®å®è¡ã«å¤±æããã¨ãã«ããã§å®è¡ãã¨ã¾ãã®ã§ä¾¿å©ã #!/bin/sh set -e perl -e 'die' echo SHOULD NOT REACH HEREã¨ãã㨠% ./hoge.sh Died at -e line 1. % echo $? 255ã¨ãªã£ã¦ãæå¾ã¾ã§ãããã«æ»ã«ã¾ãã è¤æ°ã®ã³ãã³ããé çªã«å®è¡ããã¨ãã«ä¾¿å©ã ãªãã以ä¸ã®ãããªæåããããã ããã§ãã ãã ã失æããã³ãã³ãã until ã¾ã㯠while ã«ã¼ãã®ä¸é¨ã§ããã if æã®ä¸é¨ã§ããã && ã¾ã㯠|| ãªã¹ãã®ä¸é¨ã§ããã ã³ãã³ãã®è¿ãå¤ã ! ã§å転ããã¦ã
Linuxã使ãå§ãã¦æ©ï¼å¹´ãä»ã¾ã§ä½ãæ°ã«ããLinuxæ¨æºã®bashã使ãç¶ãã¦ãã¾ãããtabã«ããã³ãã³ã/ãã¡ã¤ã«ã®è£å®æ©è½ãããã ãã§ããMS-DOSããã³ãããããã¯æç¶è¯ãã£ã¦æã£ã¦ãã¾ãããåç´ã§ãã(æ±ã ãããªç§ããä»æ¥zshã«å ¥éãã¾ãããzshã触ãå§ããã¨ããã«å¾æãã¾ãããä½ã§ãã£ã¨æ©ãzshã«switchããªãã£ãã®ãï¼ã¨ã zshã£ã¦ä½ããï¼ã£ã¦ãªæ¹ã¯ãã¨ããããã以ä¸ã®è¨äºãä¸èªããããã¨ããããããã¾ãã 横çããã°ã©ãã³ã° 第3å: å±¥æ´ãã㢠ãã®è¨äºã¯ãå ¨ææ¤ç´¢ã·ã¹ãã ã®éçºè ãé«æå²ãããæ¸ãããè¨äºã§ãã(æ¥æ¬èªãæ¬å½ã«ãä¸æã§ãã) ãã¨ã次ã®è¨äºãèªãã§ã¿ãã¨è¯ããã¨æãã¾ãã UNIX ä»æ¥ã®æ/zsh zshã®ç´°ããªèª¬æã«å ãã¦zshã®è¨å®ä¾ãåã沢山è¼ã£ã¦ãã¾ãã zshã®ä¸ã§ãä¸çªã®ãæ°ã«å ¥ãã®æ©è½ã¯ãã¿ã¼ããã«éã§ã®ã³ãã³ãå±¥æ´
#2 bashãæ¨ã¦ã¦zshã使ãã¹ããã£ã3ã¤ã®çç± å»å¹´ã ã£ããä¸æ¨å¹´ãããã ã£ããããbashãããã¦zshã使ã£ã¦ããã®ã ããå®ã¯ãã®çç±ã¨ããã®ã¯ãããããã®ã§ã¯ãªãã ä¸ã®ä¸ã«ã¯zshã使ãã¨ãããªã«å¹¸ãã«ãªãã¾ããçãªè¨äºããã£ã±ãããã®ã ããããã¾ã§ã«ã¹ã¿ãã¤ãºã«ãããè¾¼ãã»ã©æã§ããªãããbashç¨åº¦ã§ã³ãã³ãã©ã¤ã³ã¯å åãããã»ã©ä¾¿å©ãªã®ã ããã以ä¸ã®äºããããªãããããã¹ã¯ãªããã§ãæ¸ãã¦~/binã«å ¥ãã¦ããã°ããã ã§ããããªã®ã«ãªãã§zshã使ã£ã¦ããã¨ããã¨ãããã§ãbashã«ã¯ç¡ãé åãããã«ããããã ã ï¼ 1. ãã¹ããªãå ±æã§ãã: ãããããæ大ã®çç±ã ã³ãã³ãã©ã¤ã³ãCLIã®é åã®ã²ã¨ã¤ã«ãå®è¡ããã³ãã³ããä¿åãã¦ãããã¨ããã®ãããã使ãæ¹ã®ããè¦ããªã³ãã³ããªã©ãCtrl+rãæ¼ãã¦ãã¹ããªãã¤ã³ã¯ãªã¡ã³ã¿ã«æ¤ç´¢ããéå»ã«å®è¡ããã¨ãã®ãªã
ç®æ¬¡ å½ãµã¤ãã«ã¤ã㦠bash ã·ã§ã«ã¹ã¯ãªããå ¥é -ã·ã§ã«ã¹ã¯ãªããã®ããã¯- ã³ãã³ã Tips ã·ã§ã«ã¹ã¯ãªãã Tips å¤æ°ã使ç¨ãã é åã使ç¨ãã å ¥åã¨åºå if æ㨠test ã³ãã³ã for æã®ä½¿ç¨æ¹æ³ while æã®ä½¿ç¨æ¹æ³ case æã®ä½¿ç¨æ¹æ³ é¢æ°ã®ä½¿ç¨æ¹æ³ å¼æ°ãå¦çãã çµäºã¹ãã¼ã¿ã¹ ã·ã°ãã«ã¨ trap ã³ãã³ã ãã£ã«ã¿ã使ç¨ããæååæä½ 1 ãã£ã«ã¿ã使ç¨ããæååæä½ 2 æ¥ä»ãåå¾ãã æåã³ã¼ãã¨æ¹è¡ã³ã¼ã ã·ã§ã«ã¹ã¯ãªããã®ãããã° AWK ãªãã¡ã¬ã³ã¹ (Deprecated) ã·ã§ã«ã¹ã¯ãªãã ã©ã¤ãã©ãª ãether.shã ãç¥ãã Bluesky ãå§ãã¾ãã @sunone.me å¤æ´å±¥æ´ 2023.10.07 ãã¼ã¸å ãªã³ã¯ãä¿®æ£ããã 2021.02.01 ãã®ãµã¤ãã«ããã 1 ãã¼ã¸è¿½å ããããã¨æã£ã¦ãããã
ä»ã®è¨èªããæ¸ãæ £ãã¦ãããã·ã§ã«ã¹ã¯ãªãããæ¸ããã¨ããã¨ãããããªãé¨åã§ããã£ãããããã¨ãããã¾ãããç°¡åãªå¦çã ããã·ã§ã«ã¹ã¯ãªããã§æ¸ãããã¨æã£ã¦ãç¡é§ã«æéãããã£ã¦ãã¾ã£ã¦ã¯ä»æ¹ãªãã§ãããã ä»åã¯åãã¦ã·ã§ã«ã¹ã¯ãªãããæ¸ãã¨ãã«ãããããããªç¹ã«ã¤ãã¦èª¬æããããã¨æãã¾ãã å®è¡æ¨©éãã¤ãã åç´ã«ãã¡ã¤ã«ãçæãã¦ãä¸è¨ã®ç¨ã«å®è¡ãããã¨ãã¦ãå®è¡ã¯ã§ãã¾ããã # touch test # ./test sh: ./test: Permission denied # touch foo # ./foo sh: ./foo: Permission denied ããã¯ãã¡ã¤ã«ã«å®è¡æ¨©éãã¤ãã¦ããªããããèµ·ããç¾è±¡ã§ãã chmodã³ãã³ãã使ã£ã¦å®è¡æ¨©éãã¤ãã¦ããã¾ãããã # chmod +x test # ./test # chmod +x foo #
/bin/shã®å®ä½ã¨ãã¦ã¯ashï¼dashï¼ãbashãkshã®æ¡ç¨ä¾ãå¤ããã©ã®ã·ã§ã«ãBourne shellã®æ©è½ã«å ãã¦ãæ¡å¼µæ©è½ãæä¾ããã FreeBSDãªã©ã®ï¼BSDç³»ã®OSã¯ãashã/bin/shã¨ãã¦ä½¿ã£ã¦ãããashã¯POSIX.1ï¼POSIX:2008ï¼ã«ããããã®BSDæ¡å¼µæ©è½ãåãè¾¼ãã ã·ã§ã«ã ãã¡ã¢ãªããã¾ãæ¶è²»ãããé«éã«åä½ããã»ãã®ã©ã¤ãã©ãªã«ä¾åãããã¨ãå°ãªããå¾ã£ã¦ãrootãã¬ã¹ãã¥ã¼ã·ã¹ãã ã®ã¤ã³ã¿ã©ã¯ãã£ãã·ã§ã«ãã·ã¹ãã ã®ã·ã§ã«ã¹ã¯ãªããã¨ãã£ãå ´é¢ã§æ¡ç¨ããã¦ããã Mac OS Xã¯bashã/bin/shã«æ¡ç¨ãã¦ãããFedoraãopenSUSEãªã©ã®Linuxãã£ã¹ããªãã¥ã¼ã·ã§ã³ãbashã/bin/shã«æ¡ç¨ãã¦ãããLinuxãã£ã¹ããªãã¥ã¼ã·ã§ã³ã§ãUbuntuãDebianãLinux Mintãªã©ã¯ãé«éã«åä½ãã
ç§èªèº«ãéå®ãã¦ããèªä½ã·ã§ã«ã¹ã¯ãªãããç´¹ä»ãã¾ãã ä¸å¿ãå½¹ã«ç«ã¤ãã¨è¬³ã£ã¦ãã¾ãããããããªæ©è½ãªã¹ã¯ãªããã°ããã§ããå®æ ã¯ãä¸é¨ã®äººã ãã«å½¹ã«ç«ã¤ã¹ã¯ãªãã群ãã§ãã å ¨ã¦èªç±ã«ä½¿ã£ã¦é ãã¦çµæ§ã§ãã åã ã®ã¹ã¯ãªããã丸ãã¨æ²è¼ããã¹ã¿ã¤ã«ã®çºããã¼ã¸å ¨ä½ã§éè¤é¨åãå¤ããªããªãããã«ãæèçã«æ¸å¼ã«ãã©ã¨ãã£ãæããã¦ããã¾ãããã¨ãã°æååã®åãåºãã¯cut,awkã®substr,bashã®æ©è½çãæ§ã ãªæ¹æ³ãé©å½ã«ä½¿ç¨ãã¦ãã¾ãã Ubuntuã®å ´åãããã©ã«ãã§ã¯sh=dashãªã®ã§"if ["ã使ã£ã¦ããåæã¯æç´ããå¿ è¦ã§ãã ç§ã®å ´åã¯æã£åãæ©ããã®ããã« $ cd /bin ; sudo ln -sf bash sh sh=bashã«å¤æ´ãã¦ãã¾ã£ã¦å¯¾å¿ãããã¨ãå¤ãã§ãã(2010-3-4追è¨)æè¿ã¯ãããªãã§ãããã ãä»å¾ä½æãããã®ã«ã¤ãã¦ã¯bashå°ç¨
ãã¯ãããããã¯ãã±ã好ããªbokkoã§ããã§ãæè¿ã¯PSPã§éãã§ãã¾ãã ä»åã¯ã·ã§ã«ã¹ã¯ãªãããã³ãã³ãã©ã¤ã³ã§ãã使ãããã°ã©ã ã¨ãã®ä½¿ç¨ä¾ã®ç´¹ä»ã§ãã ã·ã§ã«ã¹ã¯ãªããã§ã¯æ¢ã«ããã³ãã³ããçµã¿åããã¦ããã°ã©ã ãæ¸ãã¾ããããããã·ã§ã«ã¹ã¯ãªããã¯åå²ãç¹°ãè¿ãã¨ãã£ãå¶å¾¡æ§é ãæã¡ãé¢æ°ãå¤æ°ãæ±ã£ãããååæ¼ç®ãè¡ããã¨ãã§ãã¾ãã æ¼ç® ã·ã§ã«ã¹ã¯ãªããã§æ¼ç®ãè¡ãã«ã¯exprã使ãã¾ãã add.sh #!/bin/sh A=1 B=2 C=`expr ${A} + ${B}` echo ${C} âã®add.shãå®è¡ããã¨ã $ sh test.sh 3 $ ã¨è¡¨ç¤ºããã¾ããâã®ããã«exprã®å¼æ°ãã¹ãã¼ã¹ã§åºåãã渡ãã¦ãã¾ãã¨ãåã«1+2ã¨è¡¨ç¤ºããã¦ãã¾ãã¾ãã®ã§ã注æãã¾ãããã #!/bin/sh A=1 B=2 C=`expr ${A}+${B}` ec
ã·ã§ã«ã§ï¼ä¸ã®ãã£ã¬ã¯ããªã«è¡ãã®ãããã©ãããã¦ï¼cd ../../../../ã¨ãããªãã¨ãããªãã¦ï¼æãçããï¼ ä¸ã«è¡ãããã®upã£ã¦ããã³ãã³ããä½ããã¨ã«ããï¼ ãã®1 up 3ã£ã¦ããã¨ï¼3ã¤ä¸ã«è¡ãã®ãä½ã£ãï¼ function up() { i=0 while [ $i -lt $1 ] do cd ../ i=`expr $i + 1` done } 使ãæ¹ % pwd /Users/fkd/co/dev/dotfiles % up 3 % pwd /Users/fkd %ããã¯ä½¿ãã«ããã¦ï¼cd ../../ã£ã¦æã¤ã¨ãã¯ï¼ããã¤ä¸ã«è¡ããèããªããï¼../ã£ã¦æã£ã¦ãï¼ããã ã¨ï¼å ã«æ°ãã¦ãããªãã¨ãããªãã¦ï¼é£ããã£ãï¼ ãã®ï¼ èããªããå ¥åã§ããããã«ãã¦ã¿ãï¼å¼æ°ã®æ°ã ãè¦ãï¼ function up() { i=0 while [ $i -lt $# ]
GT Nitro: Car Game Drag Raceã¯ãå ¸åçãªã«ã¼ã²ã¼ã ã§ã¯ããã¾ãããããã¯ã¹ãã¼ãããã¯ã¼ãã¹ãã«å ¨éã®ã«ã¼ã¬ã¼ã¹ã²ã¼ã ã§ãããã¬ã¼ãã¯å¿ãã¦ãããã¯ãã©ãã°ã¬ã¼ã¹ããã¤ãã¼ï¼å¤å ¸çãªã¯ã©ã·ãã¯ããæªæ¥çãªãã¼ã¹ãã¾ã§ãæãã¯ã¼ã«ã§éãè»ã¨ã«ã¼ã¬ã¼ã¹ã§ãã¾ããã¹ãã£ãã¯ã·ããããã¹ã¿ã¼ããããããè³¢ã使ã£ã¦ç«¶äºãæã¡ç ´ãå¿ è¦ãããã¾ãããã®ã«ã¼ã¬ã¼ã¹ã²ã¼ã ã¯ãã®ãªã¢ã«ãªç©çå¦ã¨ç´ æ´ãããã°ã©ãã£ãã¯ã¹ã§ããªãã®å¿ãççºããã¾ããããã¾ã§ãã¬ã¤ãããã¨ã®ãªããããªãã®ã§ãã GT Nitroã¯ããªãã¬ãã¯ã¹ã¨ã¿ã¤ãã³ã°ã試ãã«ã¼ã¬ã¼ã¹ã²ã¼ã ã§ããæ£ããç¬éã«ã®ã¢ãã·ããããã¬ã¹ãæãåãè¸ãå¿ è¦ãããã¾ããã¾ãã大ç©ãã¡ã¨ç«¶ãã¤ã¤ãè»ã®ãã¥ã¼ãã³ã°ã¨ã¢ããã°ã¬ã¼ããè¡ããªããã°ãªãã¾ãããä¸çä¸ã§æé«ã®ãã©ã¤ãã¼ã¨è»ã¨ã«ã¼ã¬ã¼ã¹ã«æããã¨ã«ãªãããã©ãã°ã¬ã¼ã¹ã®çå
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}