ã·ã§ã«ã¹ã¯ãªãããæ¸ãéã«æ°ãä»ãã¦ãããã¨8ç®æ¡
ã¨ã³ã¸ãã¢ã¨ããè·æ¥æãã·ã§ã«ã¹ã¯ãªãããæ¸ããã¨ã¯ã¡ããã¡ããããã®ã§ãããèªåãªãã«æ°ãä»ãã¦ãããã¨ãåå¿é²ï¼èªåã¸ã®æããå«ãã¦ãç°¡åã«æ¸ãã¦ã¿ããã¨æãã¾ãã
å¤æ°ã¯å¤§æå
ã·ã§ã«ã¹ã¯ãªããæ¸ãã¦ããã°å¤æ°ã®åºçªã¯è³ãã¨ããã§ããã§ãããããã®éãå¯èªæ§ãå¢ãããã«ãå¤æ°ã¯å¤§æåã使ã£ã¦ãã¾ãã
RET=`cmd1`
ã¿ããã«ã好ã¿ã®åé¡ãããã§ãããããåãããããã®ã§ã
ã¯ãªãã¼ã·ã§ã³ã¯é¸ã¶
ã¯ãªãã¼ã·ã§ã³ã«ã¯ã·ã³ã°ã«ã ã£ãããããã«ã ã£ããè²ã ããã¾ããã使ãåãã¦ãããã»ããããã§ãããã
å¤æ°ã®å±éããªãããã§ããã°ãã·ã³ã°ã«ã¯ãªã¼ãã¼ã·ã§ã³ã®ã»ããã¹ãã¼ãã§ãããããå±éãããã®ãªãããã«ã¯ãªã¼ãã¼ã·ã§ã³ã使ãã°ã¨ã
ããã«ã¯ãªã¼ãã¼ã·ã§ã³ã使ãã®ã«ãæå³ããã£ã¦ãå¤æ°ã¯ã$RETãã®ããã«ã¯ãªãã¼ã·ã§ã³ã§å²ã¾ãªãã¦ãåä½ã¯ããã¦ãããã®ã§ããã
echo "${RET}"
ã®ããã«ãã¦ãããã¨ã§ã
ã¹ãã¼ã¹ãå ¥ã£ã¦ãå¦çãã¦ãããã¨ãããã¾ã¼ãªé¢ãããã¾ããã¹ãã¼ã¹ããããã
ä¾å¤å¦çã¯å¿ããªã
ä¸è¿°ããcmd1ã§ããããã®ã³ãã³ããã¡ããã¨æ£ããå®è¡ããã¦ãã¨ã©ã¼ã«ãªã£ã¦ããªããã¯ãã§ãã¯ãã¦ãããã»ããããã§ãããã
mysqldumpã§ããã¯ã¢ããç¨ã®ã·ã§ã«ãä»æãã¦ããã®ã«ããããææã§ããªãã¨ããsshã§ä½ããªã¢ã¼ããã¹ãã«å¯¾ãã¦ã³ãã³ãçºè¡ãã¦ãã®ã«ãå®ã¯sshã§æ¥ç¶ã§ãã¦ãªãã£ãã¨ãã
è´å½çã«ãªããããªãã®ã§ãã$?ãã使ãç´åã®ã³ãã³ãã®çµäºã¹ãã¼ã¿ã¹ãå¾ã¦ãããã§æ¡ä»¶åå²ããã¦ããã®ãç¡é£ã§ãããã
ã¾ããç´åã®ã³ãã³ãã«ãã¤ããå«ã¾ããå ´åã¯ãä¸çªæå¾ã®å¦çããè¦ã¦ãããªãã®ã§ãã$?ãã使ãéã¯æåã®ã³ãã³ãã®ã¿ãã¾ãææããããç¹å®ã®ã·ã§ã«ã«éå®ããããã©ãã${PIPESTATUS[@]}ãã使ããã¨ã§è§£æ±ºããã®ãããããªã¨ã
æ¹è¡ã³ã¼ãã«æ°ãã¤ãã
Windowsã§ã³ã¼ãæ¸ãã¦ãã³ãããã¨ããå ¨ããªãã¨ã¯è¨ããªãã¦ãããããã¨ãã«æ¹è¡ã³ã¼ããæèãã¦ãªãã¨å¤§ä½æ»ã«ã¾ãããã®è¾ºã¯改行コードと「command not found」の関係について - カイワレの大冒険 Thirdã«æ¸ãã¦ã¾ããã¾ãããµã¼ãã§ç¹å®ãã£ã¬ã¯ããªããã¼ã¸ã§ã³ç®¡çãã¦ãVim使ãã°ããããããã¨ããã
å®è¡æã«ã¯ã-uããã¤ãã
/bih/sh -u test.sh
ã¿ãããªæãã§ããã¾ãããã¨ãã話ãã-uãã¤ãããã¨ã§ãå®ç¾©ããã¦ããªãå¤æ°ã使ã£ãå ´åã¯ã¨ã©ã¼ãåãããã«ãªãã¾ããããããã®ãå°å³ã«å¤§äºã§ããã
2016/05/24追è¨:
ã·ã§ãã³ã§ä»¥ä¸ã®ããã«ãã¦ãåãã§ããã
#!/bin/sh -u
ãset -eããã³ã¼ãã®é ã«æ¸ãã¦ãã
è¦ã¯ã
#/bin/sh set -e
ã¨ãã¨ãã¨ãããã¨ã§ããªããã£ã¬ã¯ããªç¡ãã®ã«ãã¡ã¤ã«ä½ããã¨ãããï¼ãã£ã¬ã¯ããªãã§ãã¯ããªãã®ãæªããã©ãï¼ãä¾å¤å¦çãçãã£ãããè²ã ããã§ãããããç°¡åãªãã§ãã¯ãªããset -eãã§ææã§ãããã¨ãã¾ããæ¬æ¥ã¯ä¸ã¤ä¸ã¤ãã§ãã¯ãã¦ããã¹ãããã»ããããã¨æãã¾ããä¾å¤å¦ç大äºã
2016/05/24追è¨:
ã·ã§ãã³ã§ä»¥ä¸ã®ããã«ãã¦ãåãã§ããã
#!/bin/sh -e
declareãé§ä½¿ãã
http://www.tldp.org/LDP/abs/html/declareref.htmlããå¼ç¨ãã¾ããããããªé¢¨ã«declareã使ã£ã¦æ¸ããã
declare -r var1=1 echo "var1 = $var1" # var1 = 1 (( var1++ )) # x.sh: line 4: var1: readonly variable
ãã®å ´åã®var1ã¯ã-rããã¤ãã¦ããã®ã§ãreadonlyã§ãããã¾ãããªã®ã§ãã¤ã³ã¯ãªã¡ã³ãã¯å½ç¶ã§ããªããã³ã¼ãã®åé ã§å®£è¨ãã¦ãããã»ããããã§ããªã
ã-iãã使ãã¨integerã§ããã¨ãè²ã å決ããããã®ã§ãæå®ãã¦ãããã»ããããã§ãããæ°å¤ã§è¿ã£ã¦ãããã¨æå¾ ãã¦ããã¨ã©ã¼æåãå¤æ°ã«å ¥ã£ã¦ããã¨ã¨ããã£ããããã®ã§ã
ã¡ãªã¿ã«ãèªã¿è¾¼ã¿å°ç¨ã¯å¤æ°å®ç¾©ããéã«ã
readonly VAL1=1
ã¨æ¸ãã¦ãããã¾ãã§ãã
ãã³ãã¬ã¼ãè£å®ã使ã
$HOME/.vimrcã«
autocmd BufNewFile *.sh 0r $HOME/dotfiles/vim_config/templates/sh.txt
ã¨æ¸ãã¦ããã¨ãã*.shããæºãããã¡ã¤ã«ãVimã§ä½æããã¨ãsh.txtãèªã¿è¾¼ã¿ããã³ãã¬ã¼ãã¨ãã¦ä½¿ããã¨ãå¯è½ã§ãã
Usageã ã£ãããAuthorã ã£ãããã#!/bih/shãORã#!/bih/bashãã ã£ãããæä½éã®ãã®ã¯ãã³ãã¬ã¼ãã¨ãã¦ç¨æãã¦ãããã»ãã楽ã§ããããã
çµããã«
ã¾ãããªããªãã¼ãããæ¸ããã¨ããããªãã£ã±ãããããã§ã¯ãªãã§ãããããããã®ã¯åãã ãã¨ããªããªãã®ã§ãå¯è½ãªç¯å²ã§ããã§ããããããªãã ããã ãã£ã¦ã·ã§ã«ã¹ã¯ãªããã¯ä¾¿å©ã ããåºçªãã¡ããã¡ããããã®ã§ãç´¹ä»ãã¦ã¿ã¾ããã
å¤åãä¸å¹´å¾ã«ã¯ãã£ã¨éããã¨æ¸ãã¦ãæ°ããããã©ããã
ééãã»ãã£ã¨ããæ¸ãæ¹ãããã°Kenichi MASUDA (@masudaK) | Twitterã¾ã§ãé¡ããã¾ãï¼
P.S. 以ä¸ã®ãµã¤ãã«ã¯ããå°ãæ¸ãã¦ãããtrapã¨ãã
www.davidpashley.com
以ä¸ã®ãµã¤ãã¯æªã èªç ´ã§ããªãã Advanced Bash-Scripting Guide
以ä¸ã®è¨äºãããããã§ãã
インフラエンジニアがアプリエンジニアに転身するにはこの3冊を勉強すれば十分だ - カイワレの大冒険 Third