Shell Scripting: Using xargs to execute parallel instances of a shell function

前端 未结 3 493
星月不相逢
星月不相逢 2021-02-05 17:54

I\'m trying to use xargs in a shell script to run parallel instances of a function I\'ve defined in the same script. The function times the fetching of a page, and so it\'s impo

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 18:17

    On Mac OS X:

    xargs: max. processes must be >0 (for: xargs -P [>0])

    f() { echo "[$@]"; }
    export -f f
    
    echo -e "b 1\nc 2\nd 3 4" | sed 's/ /\\ /g' | xargs -P 10 -n 1 -I{} bash -c f\ \{\}
    
    echo -e "b 1\nc 2\nd 3 4" | xargs -P 10 -I '{}' bash -c 'f "$@"' arg0 '{}'
    

提交回复
热议问题