Last active
December 16, 2015 07:58
-
-
Save mkacky/5402215 to your computer and use it in GitHub Desktop.
xargsでリダイレクトを行うためのワンクッション。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#################### | |
## リダイレクト先に「xargsにパイプを経由して渡した引数を含むファイル名」を設定するためのワンクッション | |
func() | |
{ | |
## コマンド及び引数の並び | |
# func <seed> | |
## 時間がかかる処理 | |
sleep 3s | |
## シミュレータが結果を出力する代わりにechoでテスト | |
echo "Simulation $1 finished !" > output_$1.txt | |
} | |
## xargsからfuncが利用できるようにexport | |
export -f func | |
## 引数(乱数の種)を0から9まで変えながら、4つまで並列に処理する | |
seq 0 9 | xargs -t -n1 -P4 -I % bash -c "func %" | |
## 以下のコマンドでは、個別ファイルが作成されない | |
## リダイレクト記号">"より右はxargsの影響外である | |
# seq 0 9 | xargs -t -n1 -P4 -I % echo "Simulation % finished" > output_%.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment