ã·ã§ã«ã§ã®æååæä½ã¡ã¢
- æååã®é·ãã調ã¹ã
STR="TEST" echo ${#STR} # 4
- æååããç¹å®ã®ç®æã®æåãæãåºã
STR="TEST" echo ${STR:0:2} # TE
ãã ãããã®æ¸ãæ¹ã¯ Bash 2.0 以éã®ã¿å¯è½ã代æ¿ã³ãã³ãã¨ã㦠GNU expr ã³ãã³ããªã以ä¸ã使ãã*1
ã¡ãªã¿ã«ãèªå®
ã® Mac + zsh ç°å¢ã ã¨ä¸ã®æ¹æ³ãä¸ã®æ¹æ³ã使ããªãã»ã»ã»ï¼ãä½ãä»ã«æ軽㫠substr çãªäºãã§ããã³ãã³ãã£ã¦ãããããã
STR="TEST" expr substr ${STR} 1 2 # TE
- å¤ãç¡ãã£ããããã©ã«ãå¤ãè¨å®
set ${STR1:="AAA"} echo ${STR1} # AAA set ${STR1:="BBB"} echo ${STR1} # AAAãâæ¢ã« AAA ãå ¥ã£ã¦ããã®ã§ BBB ã¯ã»ãããããªã
ãã使ãã¤ã
- ã·ã§ã«ã¹ã¯ãªããå¼æ°
${1}, ${2}...
å¼æ°ãã¹ã¦ã®å ´åã¯ãã
${@}
- å®è¡ãããã·ã§ã«ã¹ã¯ãªããï¼èªåèªèº«ï¼ã示ãå¤æ°
${0}
- å®è¡ãããã·ã§ã«ã¹ã¯ãªããã®ãã¹ãåå¾ãã
dirname ${0}
- 左辺ã®ã³ãã³ããæåãããå³è¾ºã®ã³ãã³ããå®è¡
command && command
- 左辺ã®ã³ãã³ãã失æãããå³è¾ºã®ã³ãã³ããå®è¡
command || command
ç¹°ãè¿ãæ
- ãã£ã¬ã¯ããªå ã®ãã¡ã¤ã«ã«å¯¾ãã¦å¦çããã
for LIST in `ls`; do echo ${LIST}; done
- æå®åæ°åå¦çããï¼ããããæ®éã® for æçãªä½¿ãæ¹ï¼
- seq ã³ãã³ãã使ç¨ããå ´åï¼redhatç³»ï¼
for i in `seq 1 5`; do echo ${i} end # 1 # 2 # 3 # 4 # 5
-
- jot ã³ãã³ãã使ç¨ããå ´åï¼BSDç³»ï¼Macå«ãï¼
seq ã¨ã¯åæå¤ã¨åæ°ã®å ´æãéã«ãªã£ã¦ãããã¨ã«æ³¨æ
for i in `jot 5 1`; do echo ${i} end # 1 # 2 # 3 # 4 # 5
æååæä½ã for ã§ã®ç¹°ãè¿ãå¦çã¯è¦ãã¦ããã¨ã¡ãã£ã¨ããå¦çãææ©ãã§ãã¦ã¨ã¦ãè¯ãã§ããã
ç¹ã«ãseq ã jot ã§ã®ç¹°ãè¿ãã¯ã¤ãæè¿ãã£ãã®ã§ããã使ãå±é¢ãå¤ãã¨æãã¾ãã
ç¶ãæ¸ãã¾ãã
id:seiunsky:20081103:1225729727
*1:ãã®é expr ã§ã¯æååã®æåã®æåã 1 ããæ°ããäºã«æ³¨æ