xargs
https://3.bp.blogspot.com/-OBSSZAfxOVo/XGjy2OinrVI/AAAAAAABRkI/G772eso1p_4UaTVPuz_KhMiTpZOqF_3igCLcBGAs/s400/kairo_heiretsu_bulb.png
æ¨æēå
ĨåãåãåãŖãĻåĻįãä¸ĻååŽčĄã§ãããŗããŗãã
ãšããŧãšããŋããĒãŠãŽįŠēįŊæåãåēåãã¨ããĻããæããĢä¸ĻååŽčĄããã
-n 1
ä¸åēĻãĢåŽčĄã§ããæ大ãŽéˇãã 1 ã¤ãĢéåŽãã
-I @
ãã¨ãĢįļããŗããŗã㎠@ ãŽé¨åãĢåēåãŖãæååãåãčžŧãã§åŽčĄãã
-P 3
ä¸ĻååŽčĄããæ大æ°ãæąēåŽãã
code:xargs.sh
echo cat dog rabbit | xargs -n 1 -I '@' echo 'line: @ is good'
line: cat is good
line: dog is good
line: rabbit is good
ãĄãĒãŋãĢ éĸæ°ãä¸ĻååŽčĄãããĢ㯠ä¸ĻååŽčĄãããéĸæ°ãäēåãĢ export ããĻããåŋ
čĻãããã
ãããããĢããŖãĻã¯ããĢããããģãšãĒãˇã§ãĢãšã¯ãĒãããããããŽã§ ææŽĩããˇã§ãĢãããĒãã¨ãã¯ãããããããĒãã
code:xargs-function.sh
# éĸæ°ãåŽįžŠ
function penguin_say() {
echo "đ§ < $@";
}
# xargs ããäŊŋãããããĢ export -f ã§éĸæ°ãã¨ã¯ãšããŧããã
export -f penguin_say
# xargs 㧠bash ãčĩˇåãã¤ã¤ãŗããŗããŠã¤ãŗã§æ¸Ąãããšã¯ãĒãããåŽčĄãã
echo cat dog rabbit | xargs -n 1 -I '@' bash -c 'penguin_say @'
đ§ < cat
đ§ < dog
đ§ < rabbit
åč